我有以下的數據幀,它不會承認與以下錯誤消息列:AttributeError: 'DataFrame' object has no attribute 'B_N'
AttributeError的 - 但據幀具有屬性
DF1
Type B_N
A AT74
A BQT1
C 0
的代碼行的錯誤是:
df1.B_N[df1['B_N'] == '0'] = np.nan
基本上我想要列B_N中的任何值爲0是一個NaN值。
任何幫助表示讚賞!
謝謝。
我有以下的數據幀,它不會承認與以下錯誤消息列:AttributeError: 'DataFrame' object has no attribute 'B_N'
AttributeError的 - 但據幀具有屬性
DF1
Type B_N
A AT74
A BQT1
C 0
的代碼行的錯誤是:
df1.B_N[df1['B_N'] == '0'] = np.nan
基本上我想要列B_N中的任何值爲0是一個NaN值。
任何幫助表示讚賞!
謝謝。
我想你想要的東西,如:
df1['B_N']=df1['B_N'].replace(0, np.nan)
例子:
>>> df1=pd.DataFrame({'B_N':['wrd','wrfe', 0], 'Type':['A', 'A', 'C']})
>>> df1
B_N Type
0 wrd A
1 wrfe A
2 0 C
>>> df1['B_N']=df1['B_N'].replace(0, np.nan)
>>> df1
B_N Type
0 wrd A
1 wrfe A
2 NaN C
我可以通過導入數據集後使用df.rename來解決此問題。感謝您的幫助。 – sschade