将丢失的日期添加到CSV文件的时间序列中
我有一个每月的时间序列的变量“ GWL”,但有几个丢失的日期。
import pandas as pd
df = pd.read_csv(r'1218_29_0.csv')
df.head(5)
date GWL
0 15/01/2001 9.73
1 15/08/2001 10.55
2 15/11/2001 11.65
3 15/01/2002 9.72
4 15/04/2002 9.92
我试图遵循其他帖子,但没有一个以CSV格式处理数据库。
如何添加缺失的日期(月)并填写NAN的价值?
I have a monthly time series of a variable 'GWL' but with several missing dates.
import pandas as pd
df = pd.read_csv(r'1218_29_0.csv')
df.head(5)
date GWL
0 15/01/2001 9.73
1 15/08/2001 10.55
2 15/11/2001 11.65
3 15/01/2002 9.72
4 15/04/2002 9.92
I have tried to follow other posts but none of them deal with a database in CSV format.
How can I add the missing dates (months) and fill their value by Nan?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我加载使用:
您需要在代码中执行的操作是将
parse_dates = ['date']
参数传递给pd.read_csv
。不要通过其他东西。我需要使用io.stringio
,因为您不会以构造函数格式提供数据。这产生:
构建以IDES为中心的每月日期范围:
REINDEX:
I load using:
What you need to do in your code is just pass the
parse_dates=['date']
parameter to yourpd.read_csv
. Don't pass the other stuff. I need to useio.StringIO
because you won't provide your data in a constructor format.This yields:
Construct an Ides-centred monthly date range:
Reindex: