zoukankan      html  css  js  c++  java
  • 问题解决:SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame

     在函数中修改:

    def countGroupWord(df_sentence):
        stop_words = list(stopwords.words('english'))
        ....
        df_sentence['classId']=df_sentence['classId']
    df_sentence['classId']=df_sentence['classId']会报错

    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

    See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
    df_sentence['classId']=df_sentence['abstract']

    这个报警主要是说,你当前对B的操作可能会改变另一个DataFrame A

    我新建一个对象再赋值就不会报错了,如果不在函数里面可以直接写df_sentence['classId']=df_sentence['abstract'],但作为函数参数修改它是不安全的(我猜是)

    def countGroupWord(df_sentence):
        stop_words = list(stopwords.words('english'))
       
        df_title = df_sentence['title'] +  df_sentence['abstract']
        df_title['classId']=df_sentence['classId']

    在main函数中执行的话就没问题

    df_data=handlData(path_Data)
    df_data['abstract']=df_data['title'];

    执行通过。

  • 相关阅读:
    Vue框架构造
    JavaScript-改变this指向
    前端发展史
    python篇第10天【For 循环语句】
    python篇第10天【While 循环语句】
    python篇第8天【运算符】
    python篇第6天【数据类型】
    python篇第5天【变量】
    Python篇函数总结【输出函数】
    python篇第3天【编码规范】
  • 原文地址:https://www.cnblogs.com/34fj/p/9945239.html
Copyright © 2011-2022 走看看