Consider the following dataframe:
| Store Number | Count |
|---|---|
| 1.0 | 121 |
| 2.0 | 85 |
| 3.0 | 32 |
| ABC | 89 |
| BCD | 94 |
| CDE | 4 |
I want to remove the '.0' from the store number. The dtype is string. I want the output to look like this:
| Store Number | Count |
|---|---|
| 1 | 121 |
| 2 | 85 |
| 3 | 32 |
| ABC | 89 |
| BCD | 94 |
| CDE | 4 |
I have tried: df = df['Store Number'].replace('.0','')
as well as: df = df['Store Number'].replace('.\d0','')
CodePudding user response:
This should work.
x = df['Store Number'].split('.')[0]
This will allow you to access the number to the left of the decimal.
CodePudding user response:
You can write it as:
df['Store Number'] = df['Store Number'].str.replace('.0','')
print(df)
Output
Store Number Count
0 1 121
1 2 85
2 3 32
3 ABC 89
4 BCD 94
5 CDE 4
