How to strip certain values from a cell in a csv file using Python?

Viewed 35

I have a csv file that has a location column that I want to manipulate using Python. The location column has 3 values in each cell (ID, county, state). I want to clean this column so that each cell only shows ID, deleting the county and state values. For example, each cell in this column currently looks like:

[locID 1, countyname, statename], [locID 2, countyname, statename], etc...

The desired outcome is that each cell would look like:

[locID 1], [locID 2], etc...

Any help is greatly appreciated, thank you!

1 Answers

You should show your code for better understanding. I don't know if you are using pandas if you are there are specific functions to do it if you're not it is possible too, you just need to replace that row with the id with a loop.

id_column = [1, 'San Antonio', 'Las Vegas']
location_column = id_column[0]
Related