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.
you can also type:
df["Coordinate"] = df["Coordinate"] + 756
@EdChum: Thanks for your comment. It kind of fired me up. I was unnecessarily complicating things for myself. Following is what I did:
df = pd.read_csv('C:/TestBook1.csv')
df = df[['Coordinate','Speed']]
df['Coordinate']+=756
df.to_csv('C:/TestBook1.csv')
Initially I was loading all the values of the column into a variable and trying to find a way to save it. After your comment I thought of experimenting and I am glad that it worked for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With