python - Pandas DataFrame 中的分组时间数据
解决方案
我想我会这样做。
import pandas as pd
# obviously you need to import the values from an external file.
time_list = ["10:00:00", "13:30:00", "09:30:00", "10:22:00", "01:00:00"]
df = pd.DataFrame({"time":time_list})
# once imported make sure to let pandas know which column contains date time.
df['time'] = pd.to_datetime(df['time'])
df.groupby([df['time'].dt.hour])
# access the date time object
df['hour'] = df['time'].dt.hour
df['hour'].replace({
1:"night",
9:"late morning",
10:"late morning",
13:"noon",
}, inplace=True)
这将返回包含“小时”列中所有类别的 Python 文件。类别必须定义为替换函数的字典类型参数。
推荐阅读
- ethereum - 我的 Uniswap 分叉不会显示我的流动资金池
- vue-formulate - Vue制定FormateForm问题
- javascript - 从一个对象数组获取或复制值到另一个对象数组
- ios - iOS上的Swift:全局队列上的任务将第二个任务添加到主队列以显示UIImageView,它不显示
- java - checkstyle插件在maven包上抛出major.minor 52错误,开发环境问题
- css - 用 css 和 vue 形成图形
- javascript - 如何在 react Native fetch 中创建自定义警报?
- c# - 如何获得总 GPU RAM(超过 4gb 内存)?
- snowflake-cloud-data-platform - 根据表 B 的拆分百分比雪花拆分表 A 的整数列
- php - 将带有名称和描述的 PHP 文本框发布到 HTML/Rest IIS 服务器