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,
Solution 1:
you can also type:
df["Coordinate"] = df["Coordinate"] + 756
Solution 2:
@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.
Solution 3:
Define path where csv file is located
Location = r'C:\\'
df = pd.read_csv(Location,header=None)
df["Coorinate"].values +756
Do not forget to import pandas package
import pandas as pd
Post a Comment for "Pandas: How To Edit Values In A Column Of A .csv File?"