我有一个数据框,其中包含 Name
和 name
列。
我正在这样做:
for i in range(len(df)):
if (some condition):
df['name'][i] = df['Name'][i]
但我收到此警告:
A value is trying to be set on a copy of a slice from a DataFrame
而且运行需要一段时间,这和警告有关吗?
我该怎么做?
最佳答案
您可以尝试loc
:
df.loc[df['name'].notnull() , 'Name'] = df['name']
对 SettingWithCopyWarning
的很好的解释.
一般来说:
df.loc[some condition , 'Name'] = df['name']
关于python - 在 pandas 的列之间复制值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34515720/