Let say this in the input CSV file.
I would like to go over the Babys
column and change it to increasing number by 1.
what i did is to count how many row there are in the file, and run a for loop on all of them. But i cant figure out how to change the values
v = open(input.csv)
r=csv.reader(v)
numline = len(v.readlines())
print (numline)
for row in r:
if row["Baby"] == "Baby":
for i in range (1, numline):
print("test")
You can use python
pandas
to increase the column number byn
:for adding
1
replacen
by1
.It can be done very easily when using pandas module
import pandas as pd
Output:
conditionally increase
Babys
column by1
Output:
increase
Babys
column by1
for all rows (unconditionally)Output:
Finally save changed DF back to CSV file:
out.csv: