You are overcomplicating the problem, just pass your dictionary into the DataFrame
constructor:
import pandas as pd
d = {'stock1': (5,6,7), 'stock2': (1,2,3),'stock3': (7,8,9)}
print(pd.DataFrame(d))
Prints:
stock1 stock2 stock3
0 5 1 7
1 6 2 8
2 7 3 9
Try this: Do not name your variables python key words!
dd = {'stock1': (5,6,7), 'stock2': (1,2,3),'stock3': (7,8,9)};
#pd.DataFrame(dd) Should work!
pd.DataFrame.from_dict(dd, orient='columns')
stock1 stock2 stock3
0 5 1 7
1 6 2 8
2 7 3 9
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.