To fix this issue I get an error whenever I try to perform actions on U objects. I always get a KeyError. I have tried many times to plot U (last statement.) , You want to use as_index=False in the groupby (or reset_index after):
In : df = pd.DataFrame([[1, 2], [1, 3], [2, 4]], columns=["A", "B"])
In : df
0 1 2
1 1 3
2 2 4
In : df.groupby("A").count()
In : df.groupby("A", as_index=False).count()
0 1 2
1 2 1
KeyError when using for loop on dataframe to plot histograms
By : CodeHunter24
Date : March 29 2020, 07:55 AM
may help you . I have a dataframe similar to: , Essentially you have two square brackets too much in your code.
should help you out The issue here is how the netCDF is written. It comes in the discrete sampling geometry (DSG) format, which is different than the typical gridded format. As a result, the mask computed here is only valid for the Lat and Long variables. For the data variables, a new mask has to be computed, based on the valid stations that remain after the initial mask is calculated. The following code adapts the original code to demonstrate this full process. Note that the loop is slow, and maybe could be refactored.