Python 什么';s相当于熊猫中的set_值,用于将字符串插入数据帧
我正在努力:Python 什么';s相当于熊猫中的set_值,用于将字符串插入数据帧,python,pandas,Python,Pandas,我正在努力: df = df.add(i, 'div', True) 但是它插入1而不是True 编辑: i是(len(df))forloop范围内的i 我正在尝试将数据帧中的元素设置为字符串 “正在尝试将数据帧中的元素设置为字符串” 这可以通过以下方式实现: for i in range(len(df["div"])): df.loc[i,"div"]= "True" print(df) >>> div 0 True 1 True 2 True 3
df = df.add(i, 'div', True)
但是它插入1
而不是True
编辑:
i是(len(df))forloop范围内的i
我正在尝试将数据帧中的元素设置为字符串
“正在尝试将数据帧中的元素设置为字符串”
这可以通过以下方式实现:
for i in range(len(df["div"])):
df.loc[i,"div"]= "True"
print(df)
>>> div
0 True
1 True
2 True
3 True
4 True
5 True
您正在尝试附加到数据帧或更改当前数据帧中的值。
i
是索引值吗?df.set_值(index=1,col=1,value='fun')我得到错误'ValueError:无法将字符串转换为float:'hidden'当值是字符串时,请显示df的一部分。告诉我们你的具体目的?