pandas 如何修复panda中“method”对象不是子脚本

b1zrtrql  于 2023-03-16  发布在  其他
关注(0)|答案(1)|浏览(121)

我的问题是,当我想从某列的单元格开始删除数字1时,它给出了这个错误,我应该怎么做来修复它?
我的代码:

S_T_1 = r"C:\Users\a.heidarzadeh\OneDrive\دسکتاپ\charisma project\excel file creat\S T+1.xlsx"
S_T_2 = r"C:\Users\a.heidarzadeh\OneDrive\دسکتاپ\charisma project\excel file creat\S T+2.xlsx"
df = pd.read_excel(S_T_1)
df['Unnamed: 5'] = df['Unnamed: 5'].str.replace["1"," "]
df

要修改的列:enter image description here我的错误:

TypeError                                 Traceback (most recent call last)
c:\Users\a.heidarzadeh\OneDrive\دسکتاپ\charisma project\excel file creat\MAIN.ipynb Cell 5 in ()
      2 S_T_2 = r"C:\Users\a.heidarzadeh\OneDrive\دسکتاپ\charisma project\excel file creat\S T+2.xlsx"
      3 df = pd.read_excel(S_T_1)
----> 4 df['Unnamed: 5'] = df['Unnamed: 5'].str.replace["1"," "]
      5 df

TypeError: 'method' object is not subscriptable

实际上,我没想到要做什么特别的事

x8diyxa7

x8diyxa71#

@MattDmo在评论中回答:
第4行应为df['Unnamed: 5'] = df['Unnamed: 5'].str.replace("1"," ")
调用函数或方法时使用圆括号(),而不是方括号[]。

相关问题