In my script, I would like to read some csv file and at the same time convert input values. But the value of one column depends on another column's (this column is not going to be converted) value. Is there any way to achieve that in read_csv or do I have to change it after csv is read?
file.csv
date total percentage
03/25/2017 100 1%
04/15/2016 200 6%
expected output
date total success
03/25/2017 100 1
04/15/2016 200 12
def convert_succes(percentage):
# is there any way to pass an 'total' value to this function?
return percentage / 100
names = ['date', 'total', 'success']
converters = {
'date': pandas.to_datetime,
'success': convert_succes,
}
input_report = pandas.read_csv('file.csv', names=names, converters=converters)