Python 2.7 熊猫阅读日期为DD-MMM-YY的CSV
我有一个数据集,在CSV文件中显示如下:Python 2.7 熊猫阅读日期为DD-MMM-YY的CSV,python-2.7,pandas,time-series,Python 2.7,Pandas,Time Series,我有一个数据集,在CSV文件中显示如下: Date Sample 01-AUG-09 Sample 1 02-Aug-09 Sample 2 etc... 使用Pandas时,我使用以下代码读取文件: in_file = pd.read_csv('File Name.csv', parse_dates = True) 但是,它无法正确识别日期列。有人知道Pandas日期分析器是否可以识别DD-MMM-YY格式的日期吗?以下内容对我有用 我想你的可能更容易解析
Date Sample
01-AUG-09 Sample 1
02-Aug-09 Sample 2
etc...
使用Pandas时,我使用以下代码读取文件:
in_file = pd.read_csv('File Name.csv', parse_dates = True)
但是,它无法正确识别日期列。有人知道Pandas日期分析器是否可以识别DD-MMM-YY格式的日期吗?以下内容对我有用 我想你的可能更容易解析,因为它们是多个标签分开的?(我做了一个精确的宽度解析,这不是小事) 制表符分隔要简单得多
In [43]: data2 = """Data\tSample\n01-AUG-09\tSample 1\n02-Aug-09\tSample 2\n"""
In [44]: read_csv(StringIO(data2),sep='\t',parse_dates=True,index_col=0)
Out[44]:
Sample
Data
2009-08-01 Sample 1
2009-08-02 Sample 2
In [43]: data2 = """Data\tSample\n01-AUG-09\tSample 1\n02-Aug-09\tSample 2\n"""
In [44]: read_csv(StringIO(data2),sep='\t',parse_dates=True,index_col=0)
Out[44]:
Sample
Data
2009-08-01 Sample 1
2009-08-02 Sample 2