Note
Pandas (44) 본문
728x90
How to select a specific column from a dataframe as a dataframe instead of a series?
# Input
df = pd.DataFrame(np.arange(20).reshape(-1, 5), columns=list('abcde'))
# Solution
type(df[['a']])
type(df.loc[:, ['a']])
type(df.iloc[:, [0]])
# Alternately the following returns a Series
type(df.a)
type(df['a'])
type(df.loc[:, 'a'])
type(df.iloc[:, 1])
'Pandas' 카테고리의 다른 글
Pandas (46) (0) | 2022.09.12 |
---|---|
Pandas (45) (0) | 2022.09.11 |
Pandas (43) (0) | 2022.09.07 |
Pandas (42) (0) | 2022.09.06 |
Pandas (41) (0) | 2022.09.04 |
Comments