我正在尝试将数据框的整个列设置为特定值。
In [1]: df
Out [1]:
issueid industry
0 001 xxx
1 002 xxx
2 003 xxx
3 004 xxx
4 005 xxx
据我所知,loc
是替换数据框中的值时的最佳做法(或者不是吗?):
In [2]: df.loc[:,'industry'] = 'yyy'
但是,我仍然收到了这条备受关注的警告信息:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_index,col_indexer] = value instead
如果我这样做
In [3]: df['industry'] = 'yyy'
我收到了同样的警告信息。
有什么想法吗?使用 Python 3.5.2 和 pandas 0.18.1。
最佳答案
您可以使用 assign
功能:
df = df.assign(industry='yyy')
关于python - 将值设置为 pandas 数据框的整列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44723183/