Note
Pandas (53) 본문
728x90
How to get the last n rows of a dataframe with row sum > 100?
# Input
df = pd.DataFrame(np.random.randint(10, 40, 60).reshape(-1, 4))
# Solution
# print row sums
rowsums = df.apply(np.sum, axis=1)
# last two rows with row sum greater than 100
last_two_rows = df.iloc[np.where(rowsums > 100)[0][-2:], :]
'Pandas' 카테고리의 다른 글
Pandas (54) (0) | 2022.10.13 |
---|---|
Pandas (52) (1) | 2022.09.21 |
Pandas (51) (1) | 2022.09.17 |
Pandas (50) (0) | 2022.09.16 |
Pandas (49) (0) | 2022.09.15 |
Comments