Please, I have a python code as shown below, to extract data from netcdf files in a given folder. The files contain data at six different atmospheric levels, the code is to extract the data for a given latitude and longitude at all the levels for all the files and store the data in a .csv file.
The problem I am having with the code is that it is only storing data in two columns! Whereas, it's suppose to be storing each time data in a separate column of the .csv fle, for instance, if I have fifteen files then I am suppose to have fifteen columns of data, but as the code is now, I could only have two columns; fourteen columns will be merged into the first column and separated with a comma while the fifteenth column will be in the second column.
I will really appreciate if anybody knows and can correct what is wrong with my code. Thanks.
import os
import netCDF4 as nc
import pandas as pd
lat = 22
lon = 66
for filename in os.listdir('.'):
if filename.endswith('.nc'):
file = os.path.join(filename)
f = nc.Dataset(file)
qm = f.variables['HSH_Tm'][0,0:6,lat-1,lon-1]
s = pd.Series(qm)
df = pd.read_csv('lat22_66_temp.csv','a')
df['Mixing'] = s
df.to_csv('lat22_66_temp.csv', index=False)
continue
else:
continue
print('Done')