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'];

    执行通过。

  • 相关阅读:
    Django_redis_session
    python_redis操作
    Django_url反向解析
    Django_分页
    Django_cookie与sesstion
    Django 自定义错误页面 403 404...
    Django_设置静态文件、上传文件
    Django设置子路由
    nginx、uwsgi
    CentOS安装MySQL
  • 原文地址:https://www.cnblogs.com/34fj/p/9945239.html
Copyright © 2011-2022 走看看