python - 使用其他数据框中的变量将函数应用于 pd 数据框中的所有列
问题描述
我有一系列数据框,有些是静态值,有些是时间序列。
我已经能够添加
我想将值从一个时间序列转换为一个新的时间序列,应用一个从原始时间序列数据帧和保存静态值的数据帧中提取值的函数。
下面是时间序列和静态数据帧的片段。
Time series dataframe (Irradiance)
Datetime Date Time GHI DIF flagR SE SA TEMP
2017-07-01 00:11:00 01.07.2017 00:11 0 0 0 -9.39 -179.97 11.1
2017-07-01 00:26:00 01.07.2017 00:26 0 0 0 -9.33 -176.47 11.0
2017-07-01 00:41:00 01.07.2017 00:41 0 0 0 -9.14 -172.98 10.9
2017-07-01 00:56:00 01.07.2017 00:56 0 0 0 -8.83 -169.51 10.9
2017-07-01 01:11:00 01.07.2017 01:11 0 0 0 -8.40 -166.04 11.0
Static dataframe (Properties)
Bearing (degrees) Inclination (degrees)
Home ID
151631 244 29
151632 244 29
151633 184 44
我已经编写了一个函数,我想用它来使用这两个值中的值填充一个新的数据框。
def dif(DIF, Inclination, GHI):
global Albedo
return DIF * (1 + math.cos(math.radians(Inclination)) / 2) + (GHI * Albedo * (1 - math.cos(math.radians(Inclination)) / 2))
当我尝试做同样的事情时,但在同一个数据帧中,我使用了 Numpy 矢量化函数,所以我认为我可以使用以下代码迭代新数据帧的每一列。
for column in DIF:
DIF[column] = np.vectorize(dif)(irradiance['DIF'], properties.iloc['Inclination (degrees)'][column], irradiance['GHI'])
相反,这会引发以下错误。
TypeError: cannot do positional indexing on <class 'pandas.core.indexes.numeric.Int64Index'> with these indexers [Inclination (degrees)] of <class 'str'>
我已经检查了 dtypes 的 Inclination(degrees) 值,但它返回为 Int64,而不是 str,所以我不确定为什么会生成此错误。
我显然在这里遗漏了一些关键的东西。有没有更好的替代方法,或者根本没有?任何帮助将非常感激。
解决方案
推荐阅读
- java - 当时间为 12 小时(下午 12 点至下午 1 点)时,24 小时日期格式的解析无法按预期工作
- python - Django AdminSite 自定义如何编辑sites.py 文件?(“适当地”)
- reactjs - 如何使用 react-i18next 翻译组件中的字符串?
- angular - 在声纳代码覆盖分析测试中排除文件 - Angular 7
- maven - 如何使用 Maven 原型锁定版本依赖/插件
- vue.js - 添加新值并在组件 Combobox vuetify 中按下 Enter 后如何限制菜单弹出
- python - sklearn OneHotEncoder 输出非数组对象错误
- c# - 无法将文件从一个目录复制到应用程序文件夹
- magento2 - Magento 2 JS 库有时无法加载
- angular - 动态配置 Angular 资产 url