Skip to content

Instantly share code, notes, and snippets.

@roycoding
Created October 5, 2017 20:46
Show Gist options
  • Save roycoding/bbecda07b594870a878f2f71f9fb15a8 to your computer and use it in GitHub Desktop.
Save roycoding/bbecda07b594870a878f2f71f9fb15a8 to your computer and use it in GitHub Desktop.
Pandas sandwich: show first and last n lines of dataframe
def sandwich(df, rows=3):
'''
Display n rows of head and tail of dataframe.
Input:
df - dataframe of interest
rows - integer number of rows from each end of dataframe to display
Output:
dataframe
'''
fill_row = pd.DataFrame(np.array(['...']*df.shape[1]).reshape(1, -1),
columns=df.columns,
index=['...'])
return pd.concat([df.head(rows), fill_row, df.tail(rows)])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment