我每15分钟记录一次温度数据。文件看起来是这样的(~50000行)
02/01/2016;05:15:00;10.800
02/01/2016;05:30:00;10.300
02/01/2016;05:45:00;9.200
02/01/2016;06:00:00;9.200
02/01/2016;06:15:00;8.900
02/01/2016;06:30:00;8.900
02/01/2016;06:45:00;9.400
02/01/2016;07:00:00;9.000
02/01/2016;07:15:00;9.200
02/01/2016;07:30:00;11.100
02/01/2016;07:45:00;13.000
02/01/2016;08:00:00;14.400
02/01/2016;08:15:00;15.600
我的目标是计算每日最小值/最大值,所以这里是我的代码
# load dataframe
with open(intraday_file_path, "r") as fl:
df_intraday = pd.read_csv(fl,
**load_args
)
df_daily = df_intraday.groupby(df_intraday[0])
df_daily = df_daily.aggregate({0:np.max})
df_daily.index.names = [0]
df_daily.reset_index(level=[0], inplace=True)
df_daily.sort_values(by=[0], inplace=True)
df_daily.drop_duplicates(subset=0,
keep="first",
inplace=True)
daily_name = "daily_%s" %(intraday_file_name,)
daily_path = os.getcwd() + "\\" + daily_name
df_daily = df_daily[0, 1]
with open(daily_path, "w") as fl:
df_daily.to_csv(fl,
**save_args
)
但当温度低于10°C时,输出就很奇怪。例如,对于02/01/2016,代码输出是9.4°C?!你知道吗
有什么想法吗?你知道吗
您的数据在最后一列中不是数字,这是一个问题。你知道吗
解决方案是使用^{} 将坏数据转换成
NaN
:为了更好地使用数据帧,还可以为列名添加参数} 。你知道吗
names
到^{仅供参考,这里有
resample
选项。方便的时间序列工具。你知道吗结果
相关问题 更多 >
编程相关推荐