티스토리 뷰
반응형
Stack Overflow에 자주 검색, 등록되는 문제들과 제가 개발 중 찾아 본 문제들 중에서 나중에도 찾아 볼 것 같은 문제들을 정리하고 있습니다.
Stack Overflow에서 가장 먼저 확인하게 되는 가장 높은 점수를 받은 Solution과 현 시점에 도움이 될 수 있는 가장 최근에 업데이트(최소 점수 확보)된 Solution을 각각 정리하였습니다.
아래 word cloud를 통해 이번 포스팅의 주요 키워드를 미리 확인하세요.
How do I get the row count of a Pandas DataFrame?
Pandas 데이터 프레임의 총 행의 수 얻기
문제 내용
How do I get the number of rows of a pandas dataframe df
?
pandas 데이터 프레임의 행 수를 얻으려면 어떻게 해야 합니까?
높은 점수를 받은 Solution
For a dataframe df
, one can use any of the following:
데이터 프레임 df의 경우 다음 중 하나를 사용할 수 있습니다.
len(df.index)
df.shape[0]
df[df.columns[0]].count()
(== number of non-NaN values in first column)
Code to reproduce the plot:
그림을 재현하기 위한 코드:
import numpy as np
import pandas as pd
import perfplot
perfplot.save(
"out.png",
setup=lambda n: pd.DataFrame(np.arange(n * 3).reshape(n, 3)),
n_range=[2**k for k in range(25)],
kernels=[
lambda df: len(df.index),
lambda df: df.shape[0],
lambda df: df[df.columns[0]].count(),
],
labels=["len(df.index)", "df.shape[0]", "df[df.columns[0]].count()"],
xlabel="Number of rows",
)
가장 최근 달린 Solution
You can do this also:
다음 작업도 수행할 수 있습니다.
Let’s say df
is your dataframe. Then df.shape
gives you the shape of your dataframe i.e (row,col)
df가 데이터 프레임이라고 가정해 보겠습니다. 그런 다음 df.shape는 데이터 프레임의 모양을 제공합니다. (행, 열).
Thus, assign the below command to get the required
따라서 다음 명령을 할당하여 필요한 명령을 가져옵니다.
row = df.shape[0], col = df.shape[1]
출처 : https://stackoverflow.com/questions/15943769/how-do-i-get-the-row-count-of-a-pandas-dataframe
반응형
'개발 > 파이썬' 카테고리의 다른 글
ImportError: numpy.core.multiarray failed to import 수정하기 (0) | 2022.12.05 |
---|---|
Pandas 데이터 프레임에서 여러 열 선택 (0) | 2022.12.05 |
딕셔너리 내포(한 줄 for문)로 만들기 (0) | 2022.12.04 |
파이썬 추상 클래스에서 추상 속성을 만드는 방법 (0) | 2022.12.04 |
키와 값이 저장된 별도 리스트로 부터 딕셔너리 만들기 (0) | 2022.12.04 |
댓글
공지사항
최근에 올라온 글