Pandas error “Can only use .str accessor with string values”

前端 未结 3 1422
暗喜
暗喜 2020-12-16 14:29

I have the following input file:

\"Name\",97.7,0A,0A,65M,0A,100M,5M,75M,100M,90M,90M,99M,90M,0#,0N#,

And I am reading it in with:



        
3条回答
  •  佛祖请我去吃肉
    2020-12-16 14:54

    In this case we have to use the str.replace() method on that series, but first we have to convert it to str type:

    df1.Patient = 's125','s45',s588','s244','s125','s123'
    df1 = pd.read_csv("C:\\Users\\Gangwar\\Desktop\\competitions\\cancer prediction\\kaggle_to_students.csv")
    df1.Patient = df1.Patient.astype(str)
    df1['Patient'] = df1['Patient'].str.replace('s','').astype(int) 
    

提交回复
热议问题