pandas 设置某列值的类型,求和指定列,给指定列赋值

number_of_declarations = df[df["测试1"]=="1"]["测试1"].astype("float").sum()#//中括号中为要求和的列
print(number_of_declarations)
# df[df["测试1"]=="1"]["测试2"]=="这是一个测试"
df.loc[df[df["测试1"] == '1'].index.tolist() ,'测试2'] = '新的值'
原文地址:https://www.cnblogs.com/lnd-blog/p/15027949.html