pandas 이용하여 python에서 excel file의 data 다루기. [2018.09.12]

Posted by 센큐
2018. 9. 12. 15:14 Mathematica&Python

pandas라는 module이 필요.


import pandas    #importing "pandas" module.


##loading dataframe from excel file


xls = pandas.ExcelFile('file path')    #put the excel file whose name is "file path" into the variable "xls".


sheetname = xls.sheet_names    #put the list of sheet names into the variable "sheetname"


df = pandas.read_excel ( xls, sheet number )    #variable df :  dataframe of sheet number in the variable "xls"



##saving dataframe to excel file


xlsx = pandas.ExcelWriter('file path')    #make excel writer 'xlsx' whose name is 'file path'


df.to_excel(xlsx, 'sheet name')    #write the dataframe df to 'xlsx' with sheet name of 'sheet name'


xlsx.save()    #save the excel file 'xlsx'