0

I have two pandas dataframes that each contain data about a series of groundwater wells. (df1) with two columns 'Well Id' and 'Surface_Elevation_mAHD' (df2) with two columns 'Well Id' and 'Adopted level'

# make a df that has the well names, elevation and ss groundwater 
`enter code here`levels
df1 = well_data_all[['Well Id','Surface_Elevation_mAHD']]
df2 = ss_well_data[['Well ID','Adopted']]

I want to make a dictionary that will hold information from both df with keys of each well name.

The problem is that there are missing rows of data in each of the df that I need to remove with dropna. When I do that, the index becomes jumbled and non-continuous.

# remove the NaNs or blank values
df1.replace(' ',np.nan,inplace=True)                                     # replace empty spaces with NaNs
df1 = df1.dropna()

For example, df1 started with 144 measurments, and before I removed the NaNs, the index went from 1 to 144 but when NaNs are removed, there are 104 measurements and instead of the index being continuous from 1- 104, it goes from 1 - 122 but there are missing index values. I have tried to reindex, but when I do that, the missing index values reappear with NaNs and when I dropnans, I am left with the same probem of a non continuous index I have tried:

x = range(1,len(df1),1)
ind=[]
for n in x:
    ind.append(n)

new_df = df1.reindex(ind)

Any help on how to make the index go from 1 to 104 would be much appreciated.

0 Answers0