Aggregation of data from CSV file using Pandas python

150 Views Asked by At

I need to process data from csv file in such a way that output should print three columns e.g. c1,c2 and c3 where c1 and c2 must use group by clause like in mysql and c3 is sum of two other columns.

I am new to python, Ideas will really help me.

1

There are 1 best solutions below

0
On

I've done a little bit of this in C#. First you open up the file and start reading lines of text. The first line in a .csv should be the header column, so handle that separately. The next lines should be your data.

Now once you have your line of text insert it into a string and then split using commas. That will give you a string array. Then make an int array by converting the strings to text. This should not be a problem as long as all data in the column are integers. If not, test for non-integer values and convert them to strings that are valid intergers. E.G. if array[0] == "no data" array[0] = "0", or array[0] = null. Then create column 3 by adding the integer values for the first and second columns together.