The script below reads a netCDF monitor file in which some information are missing and the date is used as the index and converts it to a fully usable monitor with the right index

 1from netCDF4 import Dataset
 2from pycif.utils.datastores import dump
 3from pycif.utils.netcdf import readnc
 4from pycif.utils.datastores import empty
 5from pycif.utils.datastores.dump import dump_datastore
 6import calendar
 7import os
 8import pandas as pd
 9import datetime
10import numpy as np
11import xarray as xr
12
13##### previously formatted monitor file to read
14filein = 'oldshaped_monitor.nc'
15dataread = xr.open_dataset(filein)
16dataold = dataread.to_dataframe()
17# date = previously the index, now a column
18dataold['date']=dataold.index.values 
19# example of forcing values for testing purposes
20yy = dataold['date'][0].year
21mm = dataold['date'][0].month
22dd = dataold['date'][0].day
23for i in range(len(dataold)):
24  dataold['date'][i] = datetime.datetime(year= yy, month= mm , day= dd , hour = i )
25# end forcing values
26dataold.reset_index(inplace=True)
27
28###### data to dump
29# list of infos required for in-situ, including level (either by choice of the user or because the automatic placing is not enabled)
30list_basic_cols = [ 'date', 'duration', 'station' , 'network', 'parameter', 'lon', 'lat', 'alt', 'obs', 'obserror', 'level' ]
31datadump = dataold[list_basic_cols]
32# assigning the level (here, the same for all data)
33datadump = datadump.assign(level = 2)
34
35##### dump in netcdf file for use by the CIF
36datadump = datadump.to_xarray()
37datadump.to_netcdf('monitor_lastformat.nc')
38