How do you format a float to 2 decimal points with mixed data type? I'm fetching a table and writing rows to csv file. My data is (string, string, float, float, float...)
sql = 'select * from testTable'
c.execute(sql)
columnNames = list(map(lambda x: x[0], c.description))
result = c.fetchall()
with open(outputCSVPath, 'wb') as f:
writer = csv.writer(f)
writer.writerow(columnNames)
writer.writerows(result)
With the above code, I get floats with 6 decimal places. I need to format it to 2 decimal places but because of the first 2 of the list being string, it gives me an type error.
Thank you.