import pandas as pd
# 표 ( 데이터 프레임 ) 만들기
no = [ ]
subject_name = [ ]
no.append(1)
no.append(2)
no.append(3)
subject_name.append('수학')
subject_name.append('과학')
subject_name.append('빅데이터')
subject = pd.DataFrame( )
subject['과목번호'] = no
subject['과목명'] = subject_name
print(subject)
=====================
# xls 형식으로 저장하기
subject.to_excel("C:\\Users\\miero\\Documents\\data\\subject.xls" , index=False)
=====================
# xls to xlsx
import win32com.client as win32
path="C:\\Users\\miero\\Documents\\data\\"
fname = "subject.xls"
excel = win32.gencache.EnsureDispatch('Excel.Application')
wb = excel.Workbooks.Open(path+fname)
wb.SaveAs(path+fname+"x", FileFormat = 51) #FileFormat = 51 is for .xlsx extension
wb.Close() #FileFormat = 56 is for .xls extension
excel.Application.Quit()
=====================
# xlsx 형식의 파일 내용 불러오기
import openpyxl
wb = openpyxl.load_workbook("C:\\Users\\miero\\Documents\\data\\subject.xlsx")
sheet = wb['Sheet1']
df = pd.DataFrame(sheet.values)
df
'컴퓨터 > Python' 카테고리의 다른 글
PyQt5나 PySide2를 구동하려면 올바른 plugins 경로가 지정되어야 한다. (0) | 2020.10.29 |
---|---|
pyside2 파이썬클래스 (0) | 2020.10.29 |
python win32com (0) | 2020.10.28 |
python xls 파일을 xlsx파일로 변환 (0) | 2020.10.28 |
python ?name=한글 ASCII 코드로변환 (0) | 2020.10.27 |