I have this df called result:
CODE YEAR MONTH DAY TMAX TMIN PP
9984 000130 1991 1 1 32.6 23.4 0.0
9985 000130 1991 1 2 31.2 22.4 0.0
9986 000130 1991 1 3 32.0 NaN 0.0
9987 000130 1991 1 4 32.2 23.0 0.0
9988 000130 1991 1 5 30.5 22.0 0.0
... ... ... ... ... ... ...
20118 000130 2018 9 30 31.8 21.2 NaN
30028 000132 1991 1 1 35.2 NaN 0.0
30029 000132 1991 1 2 34.6 NaN 0.0
30030 000132 1991 1 3 35.8 NaN 0.0
30031 000132 1991 1 4 34.8 NaN 0.0
... ... ... ... ... ... ...
45000 000132 2019 10 5 35.5 NaN 21.1
I want to save the data in many excel files. One excel file per code. I have 371 unique codes in CODE column.
One excel file for code 000130, another excel file for code 000132, etc etc.
I've tried this code:
for code, data in result.groupby('CODE'):
name="/PATH/TO/FILES/station"+str(code)+".xlsx"
writer = pd.ExcelWriter(name)
data.to_excel(writer,'Sheet2',index = False, header = False)
writer.save()
But it takes too long and is not working. Would you mind to help me? Thanks.