【发布时间】:2015-10-13 19:50:38
【问题描述】:
我有一个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 列,以温度为索引(A1 平均),然后变成 2 列,带有新的温度列表和一列空数据(A1 索引)。 任何想法为什么这不起作用?或者其他方法可以做到这一点?
【问题讨论】: