Created
October 5, 2017 20:46
-
-
Save roycoding/bbecda07b594870a878f2f71f9fb15a8 to your computer and use it in GitHub Desktop.
Pandas sandwich: show first and last n lines of dataframe
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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