小编wim*_*msy的帖子

为什么在我对庞大的数据框架进行修改后,这个函数"没有"?

我有一个带时间戳温度和风速值的DataFrame,以及将它们转换成"风寒"的功能.我正在使用iterrows在每一行上运行该函数,并希望通过一个漂亮的"Wind Chill"列获得一个DataFrame.

然而,虽然它似乎正在经历,并且实际上至少已经"工作"了一次,但我似乎无法一致地复制它.我觉得这是我对DataFrames结构缺失的一般情况,但我希望有人可以提供帮助.

In [28]: bigdf.head()
Out[28]: 


                           Day  Temperature  Wind Speed  Year
2003-03-01 06:00:00-05:00  1    30.27        5.27        2003
2003-03-01 07:00:00-05:00  1    30.21        4.83        2003
2003-03-01 08:00:00-05:00  1    31.81        6.09        2003
2003-03-01 09:00:00-05:00  1    34.04        6.61        2003
2003-03-01 10:00:00-05:00  1    35.31        6.97        2003
Run Code Online (Sandbox Code Playgroud)

所以我添加了一个'Wind Chill'列bigdf并预填充NaN.

In [29]: bigdf['Wind Chill'] = NaN
Run Code Online (Sandbox Code Playgroud)

然后我尝试迭代行,添加实际的风寒.

In [30]: for row_index, row in bigdf[:5].iterrows():
    ...:     row['Wind Chill'] = windchill(row['Temperature'], row['Wind Speed'])
    ...:     print row['Wind Chill']
    ...:
24.7945889994
25.1365267133
25.934114012
28.2194307516
29.5051046953
Run Code Online (Sandbox Code Playgroud)

正如您所说,新值 …

python pandas

3
推荐指数
1
解决办法
4157
查看次数

标签 统计

pandas ×1

python ×1