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

SAP ABAP 문법 정리 및 각 예제

SAP ABAP 문법 정리 및 각 예제

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

[세입자]전세 계약 체크사항

[세입자]전세 계약 체크사항

세입자를 위한 전세 계약 안전장치 및 체크리스트 전세 계약은 세입자에게 큰 금액이 투자되는 중요한 결정입니다. 아래 내용은 계약 전 확인, 계약서 작성, 안전장치, 법적 보호, 입금 시 주의사항까지 통합한 실용 가이드입니다. 1. 계약 전 주택 및 주변 환경 확인 항목체크 포인트증거 확보 방법 건물 외관외벽, 지붕, 창문 파손 여부, 균열,

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