あなたはto_timedelta
でto_datetime
を使用することができます。その後、出力のtype
がastype
によってキャスト、常にint
であればnp.timedelta64(1, 'h')
と最後でhours
にtimedelta
を変換:
#convert column Date to datetime
df['Date'] = pd.to_datetime(df.Date)
df['Ind'] = ((df.Date
- pd.to_datetime('2002-05-01')
+ pd.to_timedelta(df.Hr/100, unit='h'))/np.timedelta64(1, 'h')).astype(int)
print (df)
Date Hr CO2_resp ind
0 2002-05-01 600 0.000889 6
1 2002-05-02 600 0.000984 30
2 2002-05-04 900 0.000912 81
100
列Hr
によって分裂していない、出力が異なる場合:
df['Ind'] = ((df.Date
- pd.to_datetime('2002-05-01')
+ pd.to_timedelta(df.Hr,unit='h'))/np.timedelta64(1, 'h')).astype(int)
print (df)
Date Hr CO2_resp Ind
0 2002-05-01 600 0.000889 600
1 2002-05-02 600 0.000984 624
2 2002-05-04 900 0.000912 972
あなたはそれをロードしていますテキストファイルから?時間は通常、前にゼロがありますか? '0600'? –
@JoranBeasleyはい。時間は通常0ではありません。 – potpie