Improve readability of slice notation

master
Dan Howe 7 years ago
parent 52335b10a1
commit 8adbfd309b

@ -72,7 +72,7 @@ lat = -33.75
lon = 151.25 lon = 151.25
# Create temporary dataframe at specific location # Create temporary dataframe at specific location
df1 = df.loc[lat, lon] df1 = df.loc[(lat, lon), :]
# Plot time series # Plot time series
fig, ax = plt.subplots(1, 1, figsize=(6, 4)) 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) fig, ax = plt.subplots(3, 4)
for i, date in enumerate(dates): for i, date in enumerate(dates):
# Get temporary dataframe with only one date # Get temporary dataframe with only one date ('slice(None)' is ':')
df1 = df[df.index.get_level_values('time') == date] df1 = df.loc[(slice(None), slice(None), date), :]
# Remove date from multi-index
df1.index = df1.index.droplevel(-1)
# Split multi-index so that rows=latitude and columns=longitude # Split multi-index so that rows=latitude and columns=longitude
grid = df1.unstack() grid = df1.unstack().unstack()
# Plot colour map for current month # Plot colour map for current month
a = ax.ravel()[i] a = ax.ravel()[i]

Loading…
Cancel
Save