简体   繁体   English

带有Data_Time数据转换的Python Financial OHLC:将数组列表转换为Pandas,并为每个列表追加列名

[英]Python Financial OHLC with Data_Time data conversion: List Array to Pandas and appending column name for each

I have this raw data retreive from some source as list array enclosed by () 我有一些原始数据可以从()括起来的列表数组中获取

[('2018-10-13T21:00:00.000000000', 71.457, 72.675, 68.45 , 69.252, 71.51 , 72.725, 68.505, 69.31 , 507708)
 ('2018-10-20T21:00:00.000000000', 69.252, 69.806, 65.72 , 67.685, 69.31 , 69.855, 65.77 , 67.74 , 389174)
 ('2018-10-27T21:00:00.000000000', 67.685, 67.924, 62.61 , 62.855, 67.74 , 67.975, 62.665, 62.905, 454709)
 ('2018-11-03T21:00:00.000000000', 62.855, 64.115, 59.244, 59.815, 62.905, 64.165, 59.295, 59.87 , 858696)
 ('2018-11-10T22:00:00.000000000', 59.815, 61.262, 54.732, 56.125, 59.87 , 61.315, 54.787, 56.175, 440074)]

I want to make this as pandas data frame and add column name ,using the for loop this is achieved with desired output ,however how to do this without for loop directly using pandas built in resources and how to store this is in pandas object. 我想将其作为pandas数据框并添加列名,使用for循环可通过所需的输出来实现,但是如何使用内置资源的pandas直接在没有for循环的情况下执行此操作以及如何将其存储在pandas对象中。

for row in history:
    print("{0:s}, {1:,.5f}, {2:,.5f}, {3:,.5f}, {4:,.5f}, {5:d}".format(
    pd.to_datetime(str(row['Date'])).strftime(date_format), row['BidOpen'], row['BidHigh'],row['BidLow'], row['BidClose'], row['Volume']))

output : Here T in between the Date and Time removed and float ,decimal also take care .If not other solution how this can be stored in pandas object. 输出:这里T在删除的日期和时间之间浮动,十进制也要小心。如果没有其他解决方案,如何将其存储在pandas对象中。

Date, BidOpen, BidHigh, BidLow, BidClose, Volume
13.10.2018 21:00:00, 71.45700, 72.67500, 68.45000, 69.25200, 507708
20.10.2018 21:00:00, 69.25200, 69.80600, 65.72000, 67.68500, 389174
27.10.2018 21:00:00, 67.68500, 67.92400, 62.61000, 62.85500, 454709
03.11.2018 21:00:00, 62.85500, 64.11500, 59.24400, 59.81500, 858696
10.11.2018 22:00:00, 59.81500, 61.26200, 54.73200, 56.12500, 440074

This gives the correct output 这给出了正确的输出

df = pd.DataFrame(history, columns=['Date', 'BidOpen', 'BidHigh','BidLow', 'BidClose', 'AskOpen', 'AskHigh', 'AskLow', 'AskClose', 'Volume'])

Here the column name can be of any name. 在这里,列名可以是任何名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM