-1

I have a csv file with a lot of data I am looking to edit. I have a column (DJ in excel) that I need to multiply the numbers in the cells by 1.12. I was wondering how I could do that as I have 3800 rows in that single column. Would I have to read the current csv and write it onto a new csv?

This is the code I think I need to enter:

#skip header
next(reader, None)

#print new header
writer.writerow(['Data'])

for row in reader:
    newVal = float(row[0]) * 1.12
    writer.writerow([newVal])

Not sure how to change the values in the column.

user3822682
  • 3
  • 1
  • 4

1 Answers1

1

pandas would make this pretty trivial:

import pandas as pd
df = pd.read_csv('path/to/filename')
df['columnname'] = df['columnname']*1.12
df.to_csv('path/to/filename')

That's it.

RJT
  • 384
  • 2
  • 6