What I Do/프로그래밍

pandas] DataFrame vs. Series

1Millisecond 2023. 1. 17. 23:23

DataFrame을 사용하다 보면 Series type이 리턴될 때가 종종 있다.

DataFrame와 Series의 차이는 뭘까?

DataFrame이 Series의 상위 호환이라고 생각하면 쉽다.

Series는 column의 개수가 1개이다. (쉽게 key-value형태로 사용할 수 있음 serries.to_dict() 하면 됨.)

DataFrame은 column의 개수가 N개가 가능하다.

 

Series를 DataFrame으로 바꿀땐, Series.to_frame('column_name')으로 변경하면 된다.

series.to_frame('column_name')

참고 사이트:

https://stackoverflow.com/questions/26047209/what-is-the-difference-between-a-pandas-series-and-a-single-column-dataframe

 

What is the difference between a pandas Series and a single-column DataFrame?

Why does pandas make a distinction between a Series and a single-column DataFrame? In other words: what is the reason of existence of the Series class? I'm mainly using time series with datetime ...

stackoverflow.com