Python 我可以在数据帧中找到替换函数的替代项“.loc”替代项吗

Python 我可以在数据帧中找到替换函数的替代项“.loc”替代项吗,python,pandas,dataframe,Python,Pandas,Dataframe,以前,我在问,有3个答案,但其中3个给出了警告,通常我忽略了这一点,但这是为了生产目的,所以我不能。以下是答案和警告: 一, 警告 A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead A value is trying to be set on a copy of a slice from a Data

以前,我在问,有3个答案,但其中3个给出了警告,通常我忽略了这一点,但这是为了生产目的,所以我不能。以下是答案和警告:

一,

警告

A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
  exec(code_obj, self.user_global_ns, self.user_ns)
/home/ubuntu/anaconda3/lib/python3.6/site-packages/ipykernel_launcher.py:1: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
二,

警告

A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
  exec(code_obj, self.user_global_ns, self.user_ns)
/home/ubuntu/anaconda3/lib/python3.6/site-packages/ipykernel_launcher.py:1: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
三,

警告

A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
  exec(code_obj, self.user_global_ns, self.user_ns)
/home/ubuntu/anaconda3/lib/python3.6/site-packages/ipykernel_launcher.py:1: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

如何减少警告问题显然是在过滤前一行

解决方案
类似于:

说明


如果您稍后修改
df1
中的值,您会发现修改不会传播回原始数据(
df
),并且
Pandas
会发出警告。

问题出在上面的代码中?代码正在工作,但在我之前的功能工程部署中,jupyter notebook上需要注意,通常jupyter笔记本上的警告会给出生产上的问题。这种错误非常混乱,因为问题是前一行。显然,如果进行一些筛选,则需要
df=df1[df1['col']==10].copy()
。好的,这是可行的。你可以贴出答案