牙牙呀 发表于 2021-11-7 04:33:04

将数据类型为时间time 06:00:00的数据变成可计算的6

我想要将数据类型为时间time 06:00:00的数据变成可计算的6怎么弄啊?
{:5_109:}
大概这样 我想要计算它的mean
同时和前面的年份groupby一下

time                                                url
0   06:00:00http://en.wikipedia.org/wiki/2009_Australian_G...
1   09:00:00http://en.wikipedia.org/wiki/2009_Malaysian_Gr...
2   07:00:00http://en.wikipedia.org/wiki/2009_Chinese_Gran...
3   12:00:00http://en.wikipedia.org/wiki/2009_Bahrain_Gran...
4   12:00:00http://en.wikipedia.org/wiki/2009_Spanish_Gran...
...      ...                                                ...
105319:00:00http://en.wikipedia.org/wiki/2021_United_State...
105419:00:00http://en.wikipedia.org/wiki/2021_Mexican_Gran...
105517:00:00http://en.wikipedia.org/wiki/2021_Brazilian_Gr...
105616:00:00http://en.wikipedia.org/wiki/2021_Saudi_Arabia...
105713:00:00http://en.wikipedia.org/wiki/2021_Abu_Dhabi_Gr...

牙牙呀 发表于 2021-11-7 04:33:59

raceIdyearroundcircuitId                      name      date\
0          12009      1          1   Australian Grand Prix2009-03-29   
1          22009      2          2      Malaysian Grand Prix2009-04-05   
2          32009      3         17      Chinese Grand Prix2009-04-19   
3          42009      4          3      Bahrain Grand Prix2009-04-26   
4          52009      5          4      Spanish Grand Prix2009-05-10   
...      ...   ...    ...      ...                     ...         ...   
1053    10692021   18         69United States Grand Prix2021-10-24   
1054    10702021   19         32    Mexico City Grand Prix2021-10-31   
1055    10712021   20         18      Brazilian Grand Prix2021-11-07   
1056    10722021   22         77Saudi Arabian Grand Prix2021-12-05   
1057    10732021   23         24      Abu Dhabi Grand Prix2021-12-12   
前面是这样 我需要做一个 area plot 求助

kogawananari 发表于 2021-11-7 13:30:58

你这是电子表格还是数据库 看一下字段类型是字符串吗
电子表格公式不够用的话内置vb处理
数据库SQL server mysql Oracle之间差别很大要对应的方言去处理时间

牙牙呀 发表于 2021-11-7 14:12:53

kogawananari 发表于 2021-11-7 13:30
你这是电子表格还是数据库 看一下字段类型是字符串吗
电子表格公式不够用的话内置vb处理
数据库SQL ser ...

文字类型是字符object,
数据是电子表格csv格式
运用的jupyter notebook的python

牙牙呀 发表于 2021-11-7 14:14:18

raceIdyearroundcircuitId                      name      date\
0          12009      1          1   Australian Grand Prix2009-03-29   
1          22009      2          2      Malaysian Grand Prix2009-04-05   
2          32009      3         17      Chinese Grand Prix2009-04-19   
3          42009      4          3      Bahrain Grand Prix2009-04-26   
4          52009      5          4      Spanish Grand Prix2009-05-10   
...      ...   ...    ...      ...                     ...         ...   
1053    10692021   18         69United States Grand Prix2021-10-24   
1054    10702021   19         32    Mexico City Grand Prix2021-10-31   
1055    10712021   20         18      Brazilian Grand Prix2021-11-07   
1056    10722021   22         77Saudi Arabian Grand Prix2021-12-05   
1057    10732021   23         24      Abu Dhabi Grand Prix2021-12-12   

          time                                                url
0   06:00:00http://en.wikipedia.org/wiki/2009_Australian_G...
1   09:00:00http://en.wikipedia.org/wiki/2009_Malaysian_Gr...
2   07:00:00http://en.wikipedia.org/wiki/2009_Chinese_Gran...
3   12:00:00http://en.wikipedia.org/wiki/2009_Bahrain_Gran...
4   12:00:00http://en.wikipedia.org/wiki/2009_Spanish_Gran...
...      ...                                                ...
105319:00:00http://en.wikipedia.org/wiki/2021_United_State...
105419:00:00http://en.wikipedia.org/wiki/2021_Mexican_Gran...
105517:00:00http://en.wikipedia.org/wiki/2021_Brazilian_Gr...
105616:00:00http://en.wikipedia.org/wiki/2021_Saudi_Arabia...
105713:00:00http://en.wikipedia.org/wiki/2021_Abu_Dhabi_Gr...

牙牙呀 发表于 2021-11-7 14:15:01

<class 'pandas.core.frame.DataFrame'>
RangeIndex: 1058 entries, 0 to 1057
Data columns (total 8 columns):
#   Column   Non-Null CountDtype
---------   -------------------
0   raceId   1058 non-null   int64
1   year       1058 non-null   int64
2   round      1058 non-null   int64
3   circuitId1058 non-null   int64
4   name       1058 non-null   object
5   date       1058 non-null   object
6   time       1058 non-null   object
7   url      1058 non-null   object
dtypes: int64(4), object(4)
memory usage: 66.2+ KB

kogawananari 发表于 2021-11-7 14:38:05

说groupby我还以为是sql数据库pandas没玩过{:10_292:}

牙牙呀 发表于 2021-11-7 15:20:11

kogawananari 发表于 2021-11-7 14:38
说groupby我还以为是sql数据库pandas没玩过

太难了 学不来5555
页: [1]
查看完整版本: 将数据类型为时间time 06:00:00的数据变成可计算的6