Tarun Tarun -5 years ago 222
Python Question

Pandas: how to edit values in a column of a .csv file?

I have a .csv file which looks as follows:link

I want to open this file using pandas and edit the column Coordinate by adding a constant value of 756 to each value in it. Finally, I want the changes to be reflected in the .csv file.

How do I do that?

Edit: What I had been doing is as follows (@EdChum):

df = pd.read_csv('C:/TestBook1.csv')
df = df[['Coordinate','Speed']]

Coord = df['Coordinate']
Coord = Coord + 756

This is where I was going wrong. From here it would have been a messy affair to save changes into the .csv file.

Answer Source

you can also type:

df["Coordinate"] = df["Coordinate"] + 756
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download