【发布时间】:2019-03-16 17:26:25
【问题描述】:
这个问题类似于this one 但是,当我调整该解决方案时,我收到以下错误:
ValueError: cannot reindex from a duplicate axis
我正在尝试做这样的事情:
import pandas as pd
cols = {'foo': ['A','A','Z','A','Z'], 'bar' : [1,1,1,1,1]}
df = pd.DataFrame(data=cols)
df
bar foo
0 1 A
1 1 A
2 1 Z
3 1 A
4 1 Z
df[df['foo'] == 'Z']['bar'] = df[df['foo'] == 'Z']['bar'] * 100
C:\Anaconda3\envs\Scikit\lib\site-packages\ipykernel_launcher.py:1: SettingWithCopyWarning:
试图在 DataFrame 中的切片副本上设置值。 尝试改用 .loc[row_indexer,col_indexer] = value
请参阅文档中的注意事项:http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy """启动 IPython 内核的入口点。
【问题讨论】:
标签: pandas