I would like to unpack DataFrame, which looks like that (sample data):
As you can see there are for example 2 users who are packed in this data frame. I want to have output with as many Data Frames as I have users in the lists. So in this example I would like to have 2 Data Frames with values like that (example for the first one in the list):
And another one of course with values from the second elements of the lists. I was trying to use explode method, but it is not working as I expected.
CodePudding user response:
Use DataFrame.apply
for processing each column and select first value of tuples in indexing:
#if there are lists columns
df = df.apply(lambda x: x.str[0])
Or first remove [
and split by comma before indexing:
#if there are strings columns
df = df.apply(lambda x: x.str.strip('[').str.split(',').str[0])