我有一個存儲在數(shù)據(jù)框中的 CSV 文件。CSV 文件有一列“公司名稱”。我想創(chuàng)建一個新列并在此新列中的特定索引處插入一個值,其中公司名稱的值為 iimport pandas as pddf=pd.read_csv('Some csv.csv')df['New Column']= ' 'for i in df['Company Name']: found_list=[] for found, score, matchrow in process.extract(i, df['Company Name'], scorer=fuzz.token_set_ratio): if score >= 75: print('%d%% partial match: "%s" with "%s" ' % (score, i, found)) found_list.append(found) df['New Column'].index(i).append(found_list) #I want to insert found list in 'New Column' corresponding to value i 但這給出了錯誤:TypeError: 'RangeIndex' object is not callable
1 回答

縹緲止盈
TA貢獻2041條經驗 獲得超4個贊
您可以使用以下方法在新列中附加值 -
dataframe['new_col'] = np.nan
for i in range(0, len(dataframe)):
var = 1600
dataframe.set_value(i, 'new_col', var)
除了 dataframe.set_value(i, 'new_col', var),您還可以使用:dataframe.at[i, 'new_col'] = var
因為 dataframe.set_value() 已折舊。
可以參考文檔: https://pandas.pydata.org/pandas-docs/version/0.24.2/reference/api/pandas.DataFrame.set_value.html
https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.at.html
如果它能解決您的問題,請告訴我。
添加回答
舉報
0/150
提交
取消