1 回答

TA貢獻1909條經驗 獲得超7個贊
如果問題基本上是關于在數據框中插入另一個時間列,這將是一個解決方案:
import pandas as np
df = pd.DataFrame({'toto': ["A", "B", "C", "D"],
'titi': ["g", "t", "x", "z"],
'Energy': [180, 345, 234, 654],
'T10sec': [0.1, 0.4, 0.5, 1],
'T50sec': [5.3, 5.7, 8, 2]})
df
toto titi Energy T10sec T50sec
0 A g 180 0.1 5.3
1 B t 345 0.4 5.7
2 C x 234 0.5 8.0
3 D z 654 1.0 2.0
添加時間欄:
import numpy as np
time = 'T15sec'
if not time in df:
df[time] = np.NaN
df.iloc[:, 3:] = df.iloc[:, 3:].T.sort_index().interpolate().T
df[['toto', 'titi', 'Energy', 'T10sec', time, 'T50sec']]
toto titi Energy T10sec T15sec T50sec
0 A g 180 0.1 2.70 5.3
1 B t 345 0.4 3.05 5.7
2 C x 234 0.5 4.25 8.0
3 D z 654 1.0 1.50 2.0
添加回答
舉報