所以我用
df=data[['ID','Matrix','Name','Country', 'Units']]
df['Value']=''
我用这样的代码填充它,它在df.Matrix
中找到包含'Good'、'Bad'值的字符串,并在sch[i]
中用值填充它们:
df.loc[df.Matrix.str.contains('Good'),'Value'] = sch[2]
df.loc[df.Matrix.str.contains('Bad'),'Value'] = sch[6]
df.loc[df.Matrix.str.contains('Excellent'),'Value'] = sch[8]
我犯了很多错误,就像这两个不同的错误:
C:\Python33\lib\site-packages\pandas\core\strings.py:184: UserWarning: This pattern has match groups. To actually get the groups, use str.extract.
" groups, use str.extract.", UserWarning)
C:\Users\0\Desktop\python\Sorter.py:57: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame
df.loc[df.Matrix.str.contains('Bad'),'Value'] = sch[6]
到目前为止,我使用
pd.options.mode.chained_assignment = None
如果我不抑制错误消息,我将得到大约20条。是否有其他格式可以更改数据以避免收到错误消息?
如果有帮助的话,我正在使用python 3和pandas 0.131
以下是此警告打开的原因的详细解释:
Pandas: Chained assignments
你确定这就是你所有的代码吗?请展示一下你在做什么。
第二个例子
相关问题 更多 >
编程相关推荐