본문 바로가기
AI월드/⚙️AI BOOTCAMP_Section 1

판다스 데이터프레임에서 1줄만 잘랐을때 series가 왜 될까?

by khalidpark 2021. 1. 4.

data frame에서 1줄만 딱 slice 하면 왜 data frame이 아니라 series가 될까? (처럼 보일까?)

 

결론 : stackoverflow에 똑같은 질문과 답이 있다.

 


1. 인덱싱할때 double brakets [[ ]]



2. to_frame


 

 

 

출처 : stackoverflow.com/questions/45818612/when-slicing-a-1-row-pandas-dataframe-the-slice-becomes-a-series

 

When slicing a 1 row pandas dataframe the slice becomes a series

Why when I slice a pandas dataframe containing only 1 row, the slice becomes a pandas series? How can I keep it a dataframe? df=pd.DataFrame(data=[[1,2,3]],columns=['a','b','c']) df Out[37]: a...

stackoverflow.com

 

728x90

댓글