简单Python熊猫:将数据转换为熊猫数据帧
我已经生成了 (i) 日期:年月日 (二)价格 (iii)指示器,来自以下功能:简单Python熊猫:将数据转换为熊猫数据帧,python,numpy,pandas,Python,Numpy,Pandas,我已经生成了 (i) 日期:年月日 (二)价格 (iii)指示器,来自以下功能: (array([ 20130128., 20130129., 20130130., 20130131., 20130201., 20130204., 20130205., 20130206., 20130207., 20130208.]), array([ 56.02, 55.6 , 56. , 56.12, 56.86, 56.09, 56.2 , 56.05,
(array([ 20130128., 20130129., 20130130., 20130131., 20130201.,
20130204., 20130205., 20130206., 20130207., 20130208.]),
array([ 56.02, 55.6 , 56. , 56.12, 56.86, 56.09, 56.2 , 56.05,
55.86, 56.37]),
[-5.4958212306431209,
-5.4965882164300091,
-5.5007207046890292,
-5.5055537754993047,
-5.5111633791272423,
-5.5182838425602752,
-5.5276187056817143,
-5.5422982532120697,
-5.5530410183875532,
-5.5540498754024412])
有人能指导我如何将其转换为数据帧吗?使用字典并将其传递给数据帧对象
pd.DataFrame({'dates':pd.to_datetime([ 20130128, 20130129, 20130130, 20130131, 20130201,
20130204, 20130205, 20130206, 20130207, 20130208], format='%Y%m%d'),\
'prices':array([ 56.02, 55.6 , 56. , 56.12, 56.86, 56.09, 56.2 , 56.05,
55.86, 56.37]),\
'indicators':array([-5.4958212306431209,
-5.4965882164300091,
-5.5007207046890292,
-5.5055537754993047,
-5.5111633791272423,
-5.5182838425602752,
-5.5276187056817143,
-5.5422982532120697,
-5.5530410183875532,
-5.5540498754024412])})
非常感谢您回复Giolelm!我找到了一个解决方案:
import datetime
outt = indf #indf is the function generating the data
dates1 = pd.to_datetime(outt[0], format='%Y%m%d')
type(dates1)
dates1 = dates1.tolist()
type(dates1)
price = outt[1]
type(price)
indicator = numpy.asarray(outt[2])
type(indicator)
s1 = pd.Series(price, index=dates1)
s2 = pd.Series(indicator, index=dates1)
df = pd.concat([s1, s2], axis=1)
df.columns = ['price', 'indicator']
df
# price indicator
#2013-01-28 56.02 -5.495821
#2013-01-29 55.60 -5.496588
#2013-01-30 56.00 -5.500721
#2013-01-31 56.12 -5.505554
#2013-02-01 56.86 -5.511163
#2013-02-04 56.09 -5.518284
#2013-02-05 56.20 -5.527619
#2013-02-06 56.05 -5.542298
#2013-02-07 55.86 -5.553041
#2013-02-08 56.37 -5.554050
你试过什么吗?。这是文档处理的第一件事情。是的,但没有什么值得一提的——我对python/pandas是新手