[英]python pandas date read_table
I have the following input file: 我有以下输入文件:
2012,10,3,AAPL,BUY,200
2012,12,5,AAPL,SELL,200
How can I read this in into a pandas dataframe wth following columns: 我如何在以下列中将其读入pandas数据帧:
index: default int range # 0
column1: datetime(2012,10,3,16) # 2012-10-03 16:00
column2: string # AAPL
column3: string # BUY
column4: integer # 200
Example: 例:
0 2012-10-03 16:00 AAPL BUY 200
1 2012-12-05 16:00 AAPL SELL 200
Tried (pandas 0.7): 尝试过(熊猫0.7):
In[2]: pandas.io.parsers.read_csv("input.csv", parse_dates=[[0,1,2]], header=None)
Out[2]:
X.1 X.2 X.3 X.4 X.5 X.6
0 2012 10 3 AAPL BUY 200
1 2012 12 5 AAPL SELL 200
Try using the read_csv() function. 尝试使用read_csv()函数。 Ensure that your csv includes a header or pass header=None
for correct parsing. 确保您的csv包含标头或通过header=None
以便正确解析。 parse_dates=[[0,1,2]]
will facilitate the desired dattime parsing. parse_dates=[[0,1,2]]
将促进所需的数据时间解析。
In [4]: pandas.io.parsers.read_csv("input.csv", parse_dates=[[0,1,2]], header=None)
Out[4]:
X0_X1_X2 X3 X4 X5
0 2012-10-03 00:00:00 AAPL BUY 200
1 2012-12-05 00:00:00 AAPL SELL 200
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.