小编nlo*_*pez的帖子

Losing String column when using resample and aggregation with pandas

I have a DataFrame with the following structure:

df = df.set_index('timestamp')
print(df.head())

timestamp            id                         value
2018-12-31 23:00:00  5c8fea84763aae175afda38b   98.587768
2018-12-31 23:10:00  5c8fea84763aae175afda38b  107.232742
2018-12-31 23:20:00  5c8fea84763aae175afda38b  104.224153
2018-12-31 23:30:00  5c8fea84763aae175afda38b  104.090750
2018-12-31 23:40:00  5c8fea84763aae175afda38b   99.357023
Run Code Online (Sandbox Code Playgroud)

I need to obtain a new DataFrame with daily max and min values, as well as the mean. I have no problem in obtaining this data and I do it this way:

df = df.resample('D').agg(['min', 'max', 'mean'], columns=['value'])
Run Code Online (Sandbox Code Playgroud)

The problem is that I loose the …

python pandas

1
推荐指数
1
解决办法
62
查看次数

标签 统计

pandas ×1

python ×1