I have this df:
CODE DATE TMAX TMIN PP
0 000130 1991-01-01 32.6 23.4 0.0
1 000130 1991-01-02 31.2 22.4 0.0
2 000130 1991-01-03 32.0 NaN 0.0
3 000130 1991-01-04 32.2 23.0 0.0
4 000130 1991-01-05 30.5 22.0 0.0
... ... ... ... ...
10865 000130 2020-12-31 NaN NaN NaN
10866 000132 1991-01-01 35.2 NaN 0.0
10867 000132 1991-01-02 34.6 NaN 0.0
10868 000132 1991-01-03 35.8 NaN 0.0
10869 000132 1991-01-04 34.8 NaN 0.0
I want to convert monthly data to NaN only if there is 5 or more consecutive NaN values in a month.
For example: If January 1991 have 5 consecutive or more NaN values in column TMAX, all January 1991 values of column TMAX must be converted to NaN. Same with every month in every year. I need to do this by CODE (Every CODE values has TMAX data in January 1991, February 1991, ... December 2020). So i'm thinking in use df.groupby['CODE']
first. There are 371 codes.
For PP column i need to convert monthly data to NaN only if there is 3 or more NON consecutive NaN values in a month. For example: If January 1991 have 3 NON consecutive NaN values in column PP, all January 1991 values of column TMAX must be converted to NaN. Same with every month in every year. I also need to do this by CODE.
I'm begginer in python so i will appreciate any help.
Thanks in advance.