gpt4 book ai didi

python - AttributeError : 'DataFrame' object has no attribute 'set_value'

转载 作者:行者123 更新时间:2023-12-03 16:43:54 27 4
gpt4 key购买 nike

我正在使用flask并在set_values处出错。我正在读取html的输入并将其传递给代码

@app.route('/home', methods=['POST'])
def first():
source = request.files['first']
destination = request.files['second']
df = pd.read_csv(source)
df1 = pd.read_csv(destination)
val1 = int(request.form['val1'])
val2 = int(request.form['val2'])
val3 = int(request.form['val3'])
target = request.form['str']
df2 = df[df.columns[val2]]
count = 0
for j in df[df.columns[val1]]:
x = df1.loc[df1[df1.columns[val3]] == j].index.values
for i in x:
df1.set_value(i, target, df2[count])
count = count + 1
df1.to_csv('result.csv', index=False)

最佳答案

检查您的 Pandas 版本。
自 Pandas 0.21.0版起不推荐使用df.set_value()
而是使用df.at

import pandas as pd

df = pd.DataFrame({"A":[1, 5, 3, 4, 2],
"B":[3, 2, 4, 3, 4],
"C":[2, 2, 7, 3, 4],
"D":[4, 3, 6, 12, 7]})

df.at[2,'B']=100

A B C D
0 1 3 2 4
1 5 2 2 3
2 3 100 7 6
3 4 3 3 12
4 2 4 4 7

关于python - AttributeError : 'DataFrame' object has no attribute 'set_value' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60294463/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com