python pandas - replace number with string
pandas, python
Solution
You need to convert your column 'A' as type string.
data['A'] = data['A'].astype(str)
and then try
data['A'].replace(str(1),'s')
Problem
I have a DataFrame as; ``` data = pd.DataFrame({ 'A': [1,1,1,-1,1,1], 'B':['abc','def','ghi','jkl','mno','pqr'] }) data['A'].replace(1,2) ``` returns; ``` 0 2 1 2 2 2 3 -1 4 2 5 2 ``` But why doesn't `data['A'].replace(1,"pos")` work?