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.

martineau
  • 119,623
  • 25
  • 170
  • 301
Thao Bui
  • 11
  • 3
  • Does this help? https://stackoverflow.com/questions/27263805/pandas-column-of-lists-create-a-row-for-each-list-element – vojtam Mar 22 '21 at 08:20

2 Answers2

1
lst = [] //your list
Use df = pd.DataFrame(lst)
Atom Store
  • 961
  • 1
  • 11
  • 35
  • 1
    Don't name your variables `list`, because it can shadow the built-in type `list`. – Gino Mempin Mar 22 '21 at 09:02
  • Thank you for this code snippet, which might provide some limited, immediate help. A [proper explanation](https://meta.stackexchange.com/q/114762/9193372) 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. – Syscall Mar 22 '21 at 17:54
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
SiNcSaD
  • 11
  • 2