1

I am quite new to programming and I wanted to know if you could help me. I have a file that contains daily precipitation data from 2000 to 2020. I think with pandas I could create a dataframe that contains only the values ​​of the month of January but I can't understand how. Or maybe with CDO create a new file that only contains those values. Could someone help me? I would appreciate it

ClimateUnboxed
  • 7,106
  • 3
  • 41
  • 86

2 Answers2

5

The cdo solution would be

cdo selmon,n in.nc out.nc 

where n is the number of the month, in your case n=1, so

cdo selmon,1 in.nc out.nc 

You can also specify a list of months or a range using the forward slash, e.g.

cdo selmon,3/5 in.nc out.nc 
ClimateUnboxed
  • 7,106
  • 3
  • 41
  • 86
2

Steps -

  1. Add a month column to your dataframe

df['month']= pd.to_datetime(df['date']).dt.month

  1. Select the rows you want using the condition df.month == 1

df[(df['month'] == 1)]

Rajarshi Ghosh
  • 452
  • 1
  • 9