有没有一种很好的方法可以将序列数据(例如1PM或11AM)分别转换为 holder.textView.text = buildSpannedString {
bold { append("$name\n") }
append("$experience $dateOfJoining")
}
或类似的值(to_datetime
以外的值)到13和11
数据:
re
所需的输出:
series
1PM
11AM
2PM
6PM
6AM
series
13
11
14
18
6
出现以下错误:
pd.to_datetime(df['series'])
答案 0 :(得分:2)
您可以提供要使用的格式,格式为%I%p
:
pd.to_datetime(df['series'], format='%I%p').dt.hour
.dt.hour
[pandas-doc]将因此获得该时间戳记的小时。这给了我们:
>>> df = pd.DataFrame({'series': ['1PM', '11AM', '2PM', '6PM', '6AM']})
>>> pd.to_datetime(df['series'], format='%I%p').dt.hour
0 13
1 11
2 14
3 18
4 6
Name: series, dtype: int64