在函數中修改:
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'];
執行通過。