问题解决: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'];

执行通过。

转载于:https://www.cnblogs.com/34fj/p/9945239.html

你可能感兴趣的:(python)