python - 使用 apply 更新 Dataframe 中的行不起作用
问题描述
我似乎无法从应用函数内部更新数据帧上的行
import pandas as pd
df = pd.DataFrame({'filename':['test0.dat', 'test2.dat'],
'm':[12, 13],
'n':[None, None]})
data = {'filename':'test2.dat', 'n':16}
def update_vals(row, data=data):
if row.filename == data['filename']:
row.n = data['n']
return row
df.apply(update_vals, axis=1)
解决方案
推荐阅读
- javascript - JQuery parseXML 似乎什么也没给我
- node.js - 在路由中创建了一个 Promise,但未从其返回
- javascript - 无法使用 react-router 访问 URL 路径组件
- azure-ad-b2c - 如何使用 Graph API(或任何其他方式)读取/更新 Azure B2C MFA 电话号码
- javascript - 如何编辑tbody上的所有td
- xml - 无法使用 xpath == "//*[text()[contains(.,' "+ word + " ')]]" 找到元素
- javascript - 反应,页面没有出现
- typescript - Hapi w/ TypeScript w/o 类型断言
- angular - RangeError:Angular 4 中超出了最大调用堆栈大小
- django - 在 django 模型中创建或更新另一个表的对象时自动创建模型对象