1

I have a Dataframe as below:

                                 2021-02-01 00:00:00
0  [0.22081292351898762, 0.22248217707309176, 0.2...

I'd like to change it to:

   2021-02-01 00:00:00
0  0.22081292351898762
1  0.22248217707309176
2  0.2...
3  00000

Please give me some advises. Thank you.

1

2 Answers 2

1

Sample:

data = {'my_column': [
    [1, 2, 3],
    [4, 5, 6],
]}
df = pd.DataFrame(data)
print(df)
   my_column
0  [1, 2, 3]
1  [4, 5, 6]

Use explode:

df_explode = df.explode('my_column', ignore_index=True)
print(df_explode)
  my_column
0         1
1         2
2         3
3         4
4         5
5         6
Sign up to request clarification or add additional context in comments.

Comments

1
lst = [] //your list
Use df = pd.DataFrame(lst)

2 Comments

Don't name your variables list, because it can shadow the built-in type list.
Thank you for this code snippet, which might provide some limited, immediate help. A proper explanation would greatly improve its long-term value by showing why this is a good solution to the problem and would make it more useful to future readers with other, similar questions. Please edit your answer to add some explanation, including the assumptions you’ve made.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.