1

I have downloaded a CRU dataset as follows;

data = netCDF4.Dataset('cru_ts4.04.2011.2019.tmn.dat.nc')
print(data.variables.keys())
dict_keys(['lon', 'lat', 'time', 'tmn', 'stn'])

The time variable has 108 entries given by 12 months times 9 years. Is it possible to relabel them as month_year format, for e.g. Jan_2011, Feb_2012 etc. Kindly advise

jay
  • 1,319
  • 6
  • 23
  • 42
  • `data.variables['time']=pd.to_datetime(data.variables['time']).dt.strftime('%b_%Y')`? – Anurag Dabas Aug 08 '21 at 07:03
  • appreciate your response. can you kindly provide full example with your soln. so that I can accept it.thanks – jay Aug 08 '21 at 17:19
  • Thanks Sir btw Did the above comment works? because Sir I don't know anything about netCDF – Anurag Dabas Aug 08 '21 at 17:21
  • actually this is the error I am getting after above suggestion; TypeError: arg must be a string, datetime, list, tuple, 1-d array, or Series – jay Aug 08 '21 at 17:29

0 Answers0