pandas 应用函数导致SettingWithCopyWarning错误-?[重复]

dz6r00yl  于 2023-02-17  发布在  其他
关注(0)|答案(1)|浏览(113)
    • 此问题在此处已有答案**:

How to deal with SettingWithCopyWarning in Pandas(20个答案)
3天前关闭。
Dataframe 调用条件生成以下输出:

SUBJID                                    LBSPCCND    LBSPCCND_OTHER
0   0292-104                           Adequate specimen                  
1   1749-101                                       Other    Limited Sample
2   1733-104  Paraffin block; paraffin-embedded specimen                  
3   0587-102                                       Other  Pathology Report
4   0130-101                           Adequate specimen                  
5   0587-101                           Adequate specimen                  
6   0609-102                                       Other      Unacceptable

当我运行下面的代码时,我得到一个带有copywarning的设置:

condition["LBSPCCND"] = condition["LBSPCCND"].apply(convert_condition) 
condition

      SUBJID           LBSPCCND    LBSPCCND_OTHER
0   0292-104           ADEQUATE                  
1   1749-101              Other    Limited Sample
2   1733-104  PARAFFIN-EMBEDDED                  
3   0587-102              Other  Pathology Report
4   0130-101           ADEQUATE                  
5   0587-101           ADEQUATE                  
6   0609-102              Other      Unacceptable

这将生成以下错误:

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
gab6jxml

gab6jxml1#

我的 Dataframe 的Copy()消除了错误:

columns = ["SUBJID", "LBSPCCND", "LBSPCCND_OTHER"]
condition = igan[columns].copy()

相关问题