Recently I had an interview task that I should read a huge csv and aggregate some columns and write it in a new csv file I did the code in pandas using chunks but they said the method is not good and I need to use chunks (while i did). now I am confused what is the problem with my method:
df = pd.read_csv(file, usecols=['Department Name', 'Number of sales'], chunksize=100)
pieces = [x.groupby('Department Name')['Number of sales'].agg(['sum']) for x in df]
result = pd.concat(pieces).groupby(level=0).sum().rename(columns={'sum': 'Total Number of Sale'})
result.to_csv('output.csv')