没有正确解析日期列

时间:2017-07-22 02:21:29

标签: python

我正在将csv导入pandas数据帧。它没有正确导入我的日期列。 我的CSV数据

window.onpopstate = function(e)
{
 if (id_('editor') && is_node_parent(document.activeElement,id_('editor')))
 {
  e.preventDefault();
  history.go(1);
 }
}

AAAP,27分之12/ 2016,26.29,263,6.12,0,-165.77,23.51,-2.49,-4.95,-2.53,-2.71,0.51,24.39,1 ABMD 2/6 / 2017,110.5,261,3,1,-128.78,103.82,0.54,-1.15,-0.76,-1.6,-2,105.93,30 AIMC,4/11 / 2017,38.55,50,2.67,0,-20.65,37.6,-0.52,-2.46,-2.2,-3.37,-2.85,38.25,162

我在第二栏中有一个日期。

Ticker,Date_Time,Close,volume rate,Volatility,breakouthappened,prevdaycci negative,stopprice,day1gainpotential,day1closegainpotential,day2gainpotential,day3gainpotential,day4gainpotential,breakoutpoint,#

1 个答案:

答案 0 :(得分:0)

我对此并不太熟悉。但我可以给你一些帮我解决这个问题的东西。 您可以编写解析器方法并在读取时将字符串转换为datetime对象。

date_format = '%Y-%m-%d'
parser = lambda x: pd .datetime.strptime(x, date_format)

在阅读时打电话给它。 (假设具有日期的列是索引0。

potential_trades_df=pd.read_csv('/path/to/file.csv',parse_dates=[0], date_parser=parser)

这样做对我有用

编辑:您在代码中编写的日期格式似乎与您的示例中的日期格式不同。在您的示例中,date_format为"%m/%d/%Y"