"Pandas 엑셀"의 두 판 사이의 차이
DB CAFE
1번째 줄: | 1번째 줄: | ||
− | + | == pandas + 엑셀 파일 읽고 쓰기 == | |
− | + | === 엑셀 읽기 === | |
+ | * 파이썬 모듈 설치 | ||
+ | <source lang=python> | ||
+ | pip install pandas | ||
+ | pip install xlrd | ||
+ | pip install openpyxl | ||
+ | </source> | ||
+ | * 코드 | ||
+ | <source lang=python> | ||
+ | import pandas as pd | ||
+ | |||
+ | df = pd.read_excel('test.xlsx', sheet_name="Sheet1", engine='openpyxl') | ||
+ | |||
+ | print(df) | ||
+ | </source> | ||
+ | |||
+ | === 엑셀 쓰기 === | ||
+ | <source lang=python> | ||
+ | import pandas as pd | ||
+ | |||
+ | df = pd.read_excel('test.xlsx', sheet_name="Sheet1", engine='openpyxl') | ||
+ | |||
+ | print(df) | ||
+ | |||
+ | df['전재산'] = df['전재산']/2 | ||
+ | |||
+ | print(df) | ||
+ | |||
+ | df.to_excel('test.xlsx', sheet_name="Sheet1", index=False) | ||
+ | </source> | ||
[[category:Python]] | [[category:Python]] |
2023년 7월 24일 (월) 17:22 판
thumb_up 추천메뉴 바로가기
- DBA { Oracle DBA 명령어 > DBA 초급 과정 > DBA 고급 과정 }
- 튜닝 { 오라클 튜닝 목록 }
- 모델링 { 데이터 모델링 가이드 }
1 pandas + 엑셀 파일 읽고 쓰기[편집]
1.1 엑셀 읽기[편집]
- 파이썬 모듈 설치
pip install pandas
pip install xlrd
pip install openpyxl
- 코드
import pandas as pd
df = pd.read_excel('test.xlsx', sheet_name="Sheet1", engine='openpyxl')
print(df)
1.2 엑셀 쓰기[편집]
import pandas as pd
df = pd.read_excel('test.xlsx', sheet_name="Sheet1", engine='openpyxl')
print(df)
df['전재산'] = df['전재산']/2
print(df)
df.to_excel('test.xlsx', sheet_name="Sheet1", index=False)