From 8adbfd309b46c02ebaec3e0030892a285abdb689 Mon Sep 17 00:00:00 2001 From: Dan Howe Date: Wed, 20 Jun 2018 08:58:24 +1000 Subject: [PATCH] Improve readability of slice notation --- README.md | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 1a7b981..50bed57 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,7 @@ lat = -33.75 lon = 151.25 # Create temporary dataframe at specific location -df1 = df.loc[lat, lon] +df1 = df.loc[(lat, lon), :] # Plot time series fig, ax = plt.subplots(1, 1, figsize=(6, 4)) @@ -112,14 +112,11 @@ dates = df.index.get_level_values('time').unique() fig, ax = plt.subplots(3, 4) for i, date in enumerate(dates): - # Get temporary dataframe with only one date - df1 = df[df.index.get_level_values('time') == date] - - # Remove date from multi-index - df1.index = df1.index.droplevel(-1) + # Get temporary dataframe with only one date ('slice(None)' is ':') + df1 = df.loc[(slice(None), slice(None), date), :] # Split multi-index so that rows=latitude and columns=longitude - grid = df1.unstack() + grid = df1.unstack().unstack() # Plot colour map for current month a = ax.ravel()[i]