I am trying to standardize my data in my csv file:
import pandas as pd
my_city = pd.read_csv('sample4_addlink.csv')['City'].unique()
my_city
Out[70]:
array(['Lancaster', 'Canton', 'Edison', ..., 'Upton', 'Irvington',
'El Cerrito'], dtype=object)
Now as you see in my_city, there are some cities with space between names like El Cerrito. I want to replace the space with an underscore
my_cities =my_city.replace(" ", "_")
Traceback (most recent call last):
File "<ipython-input-71-53c4a0662dd7>", line 1, in <module>
my_cities =my_city.replace(" ", "_")
AttributeError: 'numpy.ndarray' object has no attribute 'replace'
I get this error when I use the .replace function. What is the best way to get around this?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.