这是我关于StackOverflow的第一篇文章。如果我做错了什么或违反了网络规则,我表示歉意。
我的问题是:我在python中使用pandas
读取了一个csv文件。dataframe有五列,名为[yday, wday, time, stop, N]
:
yday
是一年中的一天,从1到365wday
是一周中的一天,从1到7time
是一个1-144之间的数字(我把一天分成10分钟的间隔,每天1440分钟/10分钟=144)stop
是公共汽车站的编号(1-4)N
是进入总线的ppl数
好吧,我想为每个间隙设置一个条目,每天给出144行,但我有一些缺失的间隙,如您所见: CSV example
我的目标是添加新行以填补所有时间间隔,例如添加(基于给定的图像):
320,6,81,1,1 <-- Exists
320,6,82,1,na <-- New
320,6,83,1,na <-- New
320,6,84,1,na <-- New
320,6,85,1,1 <-- Exists
我试图用df.set_index['stop','yday','time']
索引我的DataFrame
,这样我就可以用'time'
值从1
重新索引到144
,但它不起作用。我是Python新手,想解决这个问题我都快疯了
提前谢谢,我的英语很抱歉
抱歉代码太长。但它解决了你的目的:
输出:
干杯
相关问题 更多 >
编程相关推荐