Skip to content
Advertisement

Not able to read data to csv file using pandas

I have a below data in table need to read entire data in table to pandas after performing cumulative sum and average need to generate csv file [ comma separated file with headers ]

I tried to write got stuck

Expected output in csv file with headers

When i do print(fd) , it gives below output

Advertisement

Answer

Seems like you are struggling to create csv file from table result

Where in your table as only 3 columns , so specify the column names in your query instead of '*'.

And the CUM and AVG you are getting it from the query result based on MARKS column dynamically using pandas functions and that you wanted in csv file , if that’s the requirement you are looking for then below code will work for you

If throws any error let me know

May be this code will work for you

Note : If their is no data in table the csv file will be created with only HEADER as a record

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement