• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: Explode elements in braces/curly brackets separated by comma and no space (e.g. {a,b})

Resolved: Explode elements in braces/curly brackets separated by comma and no space (e.g. {a,b})

0
By Isaac Tonny on 17/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

I have a DataFrame that looks somewhat like this:
I want to remove the braces/curly brackets and explode each of the elements into its own row. So it would look something like this in the end:
I have tried to first eliminate the curly brackets with
then expand/explode the elements with
I have tried more ways to fix the latter part. However, I think even if it works, the code still does a very inefficient job as it takes a bit long (~ 2mins) on my dataset of around 10k rows. Is there a better approach to this?

Answer:

You can just use a combination of apply and explode functions:
EDIT: Figured out the explode has an ignore_index keyword that can be useful in this case.

If you have better answer, please add a comment about this, thank you!

dataframe pandas python
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: Why reference in pointer array doesn’t have data?

24/03/2023

Resolved: EntityFramework creates/runs migrations using parameterless DataContext instance

24/03/2023

Resolved: Visual Studio 2022 crashes when using breakpoints

24/03/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.