Created
August 6, 2021 13:12
-
-
Save diije/0444be68c162e4ffefec8ddeaf90af99 to your computer and use it in GitHub Desktop.
Display k first rows of Pandas dataframe and sum of other rows
This file contains 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
# Number of rows to keep | |
k = 8 | |
# Keep k first rows + transpose df | |
temp = df.head(k).T | |
# If df has more than k rows, sum remaining rows | |
if len(df) > k: | |
temp['Other rows'] = df.tail(len(df)-k).sum() | |
# Transpose back | |
temp = temp.T | |
temp |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment