python - 操作列和行
问题描述
def Resample_10mins(df, ZTD_station):
# ensure the time column is in the right format
df['Date'] = pd.to_datetime(df.Date)
# round to the nearest 10 minute interval
# if you want to floor / ceil the time, you may use
#`dt.floor` or `dt.ceil` instead of `dt.round`
df['rounded_to_nearest_10_min'] = df.Date.dt.round('10min')
# to get the mean of all columns
df = df.groupby('rounded_to_nearest_10_min').agg('mean')
# to get the mean of a specific column
df = df.groupby('rounded_to_nearest_10_min').agg({ZTD_station: 'mean'})
# Rename date column
df = df.rename(columns={df.columns[0]: 'Date' })
# df.rename(columns={'rounded_to_nearest_10_min': 'Date'}, inplace=True)
return df
我有以下代码,用于将数据帧从 30 秒重新采样到 10 分钟。但是,我注意到列和行结构发生了变化(比较第二个和第三个数据帧)我想要第二个而不是第三个的结构。
Date GNSS_BIEL
0 2011-01-01 00:00:00 2.247777
1 2011-01-01 00:00:30 2.246933
2 2011-01-01 00:01:00 2.245638
3 2011-01-01 00:01:30 2.244568
4 2011-01-01 00:02:00 2.243413
Date
rounded_to_nearest_10_min
2011-01-01 00:00:00 2.244251
2011-01-01 00:10:00 2.242808
2011-01-01 00:20:00 2.242657
2011-01-01 00:30:00 2.243564
2011-01-01 00:40:00 2.249966
解决方案
推荐阅读
- awk - 如何匹配列字段并将它们的值组合在一起?
- html - 如何删除此 HTML 项目中的空白间隙
- c++ - 模板化放置 new - 调用析构函数
- javascript - 为什么我不能映射这个数组
- c# - 如何将 Azure Cosmos DB 查询记录集映射到 C# 类对象
- adobe - Adobe SDK - 打印 PDF - 设置文件名 - avDoc.PrintPagesSilent(0, pdDoc.GetNumPages() - 1, 2, 1, 1);
- json - 如何为网站构建解析信息以聊天不和谐?
- cmake - 如何修复 CMakeList 以使用 SDL_image 构建项目?
- ssl - 具有证书加密和 IP 白名单的 haproxy 反向代理
- javascript - 如何在 NightWatch 中循环比较字符串