我有一个字典列表,其中包含我在 Pandas 中转换为数据框的值。我还将日期信息(此处以毫秒为单位)转换为日期时间并设置新索引。这些值每 5 秒记录一次。当我想将它们重新采样到 1 分钟时,我收到错误消息“DataError:没有要聚合的数字类型”,我不明白为什么。在这里你可以看到我的代码:
import pandas as pd
#convert list of dictionaries into a dataframe
dataframe = pd.DataFrame(data)
#convert the date-information (here measured in ms) to datetime
dataframe['timestamp'] = pd.to_datetime(dataframe['timestamp'], unit='ms')
#rearrange the columns
dataframe = dataframe.reindex(['timestamp','value'], axis=1)
#set the index to the column 'timestamp'
dataframe.set_index('timestamp', inplace=True)
#resample to a resolution of 1 minute
dataframe_minutes = dataframe.resample('1M').mean()
有问题的部分是最后一行 dataframe_minutes = dataframe.resample('1M').mean()
。在此之前,数据框如下所示:
你有什么想法,为什么我会收到这个错误,因为据我所知,两列都有数值。我很感激每一条评论。