2
我有一個dataset ,溫度爲一列。由於加熱器的工作原理,數據中存在一些缺陷。爲了直接比較不同的數據集,我想填寫這些缺失的溫度,並在另一列中添加相應的NaN。通過重新索引將行插入數據框
我試過使用這裏給出的答案,這似乎正是我想要的:link。 但是,這並不工作 - 我得到了新的溫度值,我希望有一個數據幀,但相應的數據已經:
import pandas as pd
import numpy as np
A1 = pd.read_table('Test data.tsv', encoding='ISO-8859-1', header = 2)
A1.columns = ['time',2,3,4,5,6,7,'freq',9,10,11,12,13,'temp',15,16,17,18,19]
A1truncated = A1[A1.temp >= 25]; A1truncated=A1truncated[A1truncated.temp <= 350.1]
A1averaged = A1truncated.groupby(['temp'], as_index=False)['freq'].mean()
A1averaged = np.around(A1averaged, decimals=1)
A1averaged.set_index('temp')
new_index = pd.Index(np.arange(25, 350, 0.1), name='temp')
A1indexed = A1averaged.set_index('temp').reindex(new_index).reset_index()
打開我的19列到1溫度指數( A1averaged),然後分成2列,新的溫度列表和一列空數據(A1索引)。 任何想法爲什麼這不起作用?或另一種方法來做同樣的事情?
完美,非常感謝!我永遠不會注意到浮動問題 – Yobmod