[英]select rows by date with Pandas read_csv
我有一个csv文件(列:日期,价格,x,y,z),我想只阅读属于特定时间段的行。 我尝试了这个:
...
abc1 = pandas.read_csv(filesource1, parse_dates=['Date'])
abc2 = abc1.price
startDate = datetime(2014,8,1)
endDate = datetime(2018,3,1)
daterange = pandas.date_range(startDate,endDate)
abc3 = abc2[daterange]
print (abc3.head())
这给了我一个列表,其中仅包括日期,价格为“ NaN”。 如何正确地做到这一点?
我用以下补充解决了它:
abc1 = pandas.read_csv(filesource1, parse_dates=['Date'], index_col=['Date'], usecols=['Date', 'Price'])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.