python pandas 라이브러리를 이용한 엑셀(excel)파일 읽어들이기.

python pandas 라이브러리를 이용한 엑셀(excel)파일 읽어들이기.

1. python Pandas 라이브러리 설치하기

   : pip install pandas
pip install xlrd

2. 샘플 엑셀파일 받기   

movies.xls를 열면 이런식으로 되어있음
3. 소스보고 따라해보기

(위에 다운받은 파일을 넣은 폴더안에 임의의 python 파일을 만들어서 붙여넣는다)

import pandas as pd

excel_file = 'movies.xls'
movies = pd.read_excel(excel_file)
print(movies.head())
print(movies.shape)

print('---------------------------------------------------------------')
#sheet1 을 읽어온다.
movies_sheet1 = pd.read_excel(excel_file, sheet_name=0, index_col=0)
print(movies_sheet1.head())
print(movies_sheet1.shape)

print('---------------------------------------------------------------')
#sheet2 을 읽어온다
movies_sheet2 = pd.read_excel(excel_file, sheet_name=1, index_col=0)
print(movies_sheet2.head())
print(movies_sheet2.shape)

print('---------------------------------------------------------------')
#sheet3 을 읽어온다.
movies_sheet3 = pd.read_excel(excel_file, sheet_name=2, index_col=0)
print(movies_sheet3.head())
print(movies_sheet3.shape)

print('--------------------------------------------------------------')
#위의 sheet1, 2, 3 을 모두 합친다.
movies = pd.concat([movies_sheet1, movies_sheet2, movies_sheet3])
print(movies.shape)

————————————  실행결과 --------------------------------------------------

D:\ProgramData\miniconda3\python.exe D:/02_Workspace/python/ptest/movie.py
                                               Title  ...  IMDB Score
0  Intolerance: Love's Struggle Throughout the Ages   ...         8.0
1                    Over the Hill to the Poorhouse   ...         4.8
2                                    The Big Parade   ...         8.3
3                                        Metropolis   ...         8.3
4                                     Pandora's Box   ...         8.0

[5 rows x 25 columns]
(1338, 25)
---------------------------------------------------------------
                                                   Year  ... IMDB Score
Title                                                    ...           
Intolerance: Love's Struggle Throughout the Ages   1916  ...        8.0
Over the Hill to the Poorhouse                     1920  ...        4.8
The Big Parade                                     1925  ...        8.3
Metropolis                                         1927  ...        8.3
Pandora's Box                                      1929  ...        8.0

[5 rows x 24 columns]
(1338, 24)
---------------------------------------------------------------
                        Year  ... IMDB Score
Title                         ...           
102 Dalmatians          2000  ...        4.8
28 Days                 2000  ...        6.0
3 Strikes               2000  ...        4.0
Aberdeen                2000  ...        7.3
All the Pretty Horses   2000  ...        5.8

[5 rows x 24 columns]
(2100, 24)
---------------------------------------------------------------
                                        Year  ... IMDB Score
Title                                         ...           
127 Hours                             2010.0  ...        7.6
3 Backyards                           2010.0  ...        5.2
3                                     2010.0  ...        6.8
8: The Mormon Proposition             2010.0  ...        7.1
A Turtle's Tale: Sammy's Adventures   2010.0  ...        6.1

[5 rows x 24 columns]
(1604, 24)
--------------------------------------------------------------
(5042, 24)

Process finished with exit code 0

 

만족하셨나요? ~~~~~~~

#pandas #Python Pandas #Python Excel 읽기

Read more

마인츠(Mainz) 여행

마인츠(Mainz) 여행

라인강의 심장, 마인츠(Mainz) 여행: 역사와 와인, 문화가 숨 쉬는 보석 같은 도시 🇩🇪 마인츠(Mainz), 어떤 도시인가요? 독일 서부, 라인강과 마인강이 만나는 지점에 자리 잡은 마인츠는 천 년이 넘는 역사와 현대적인 활력이 공존하는 매력적인 도시입니다. 요하네스 구텐베르크의 인쇄술 발명으로 인류 문명사에 혁명적인 기여를 한 곳이자, 독일 최대 와인 생산지인 라인헤센(

SAP ABAP 문법 정리 및 각 예제

SAP ABAP 문법 정리 및 각 예제

SAP ABAP 문법 정리: 초보자부터 숙련자도 참고 가능 SAP 시스템은 전 세계 수많은 기업의 핵심 비즈니스 프로세스를 구동하는 강력한 솔루션입니다. 그리고 이 SAP 시스템의 심장부에는 바로 **ABAP(Advanced Business Application Programming)**이라는 독자적인 프로그래밍 언어가 있습니다. ABAP은 단순히 보고서를 생성하는 것을 넘어, 복잡한 비즈니스 로직 구현, 데이터베이스 상호작용, 사용자 인터페이스

Image 3
이 포스팅은 쿠팡 파트너스 활동의 일환으로, 이에 따른 일정액의 수수료를 제공받습니다.
Image 4
이 포스팅은 쿠팡 파트너스 활동의 일환으로, 이에 따른 일정액의 수수료를 제공받습니다.