Reshape your dataframe to wide and long formats

#Reshape-your-dataframe-to-wide-and-long-formats

Driven by Ted Petrou's Minimally Sufficient Pandas approach I will also preach that I as well feel strongly that Minimally Sufficient Pandas is a useful guide for those wanting to increase their effectiveness at data analysis without getting lost in the syntax.

Loading output library...

Long to wide dataframe format with pivot_table

#Long-to-wide-dataframe-format-with-

Let’s use the pivot method to reshape this data so that the purpose of the wells become columns names and the water_depth becomes their respective values.

Guidance — Consider using only pivot_table and not pivot.

pivot_table can accomplish all of what pivot can do. In the case that you do not need to perform an aggregation, you still must provide an aggregation function.

Before:

Loading output library...

Column purpose has 3 values - WILDCAT, APPRAISAL and WILDCAT-CCS so we are expecting 3 new columns after applying pivot_table method.

Loading output library...
Loading output library...

After:

Loading output library...
Loading output library...

Wide to long dataframe format with melt

#Wide-to-long-dataframe-format-with-

Now we will go back to the original long format. In addition we will drop values where water_depth_m is na with .dropna.

Loading output library...
Loading output library...