TransWikia.com

How to fix dict to pandas dataframe

Stack Overflow Asked by Spatial Digger on February 23, 2021

I have some data that look like this:

{'open_time': [0     2021-02-14 19:30:00
1     2021-02-14 19:31:00
2     2021-02-14 19:32:00
3     2021-02-14 19:33:00
4     2021-02-14 19:34:00
              ...        
494   2021-02-15 03:44:00
495   2021-02-15 03:45:00
496   2021-02-15 03:46:00
497   2021-02-15 03:47:00
498   2021-02-15 03:48:00
Name: 0, Length: 499, dtype: datetime64[ns]], 'open': [0      4.195
1      4.192
2      4.192
3      4.195
4      4.196

I try to turn it into a dataframe:

h_kline = pd.DataFrame(data)

but all the data end up as a sinfgle row in the column like: 0 2021-02-14 19:31:00n1 2021-02-14 19:32:00n2 etc.

Where have I gone wrong?

The dictionary was constructed like this:

data = {'open_time': [open_time], 'open': [open], 'high': [high], 'low': [low], 'close': [close], 'close_time': [close_time], 'volumne': [volume]}

the values in [ ] are pandas series

One Answer

If you give the DataFrame method a dictionary, the keys will be the columns and the values the rows. If you want to specify the order of the columns in your new data frame, you can also specify a columns parameter and set it to the list of column header labels.

Answered by not_overrated on February 23, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP