How to convert below python code into function, so that when i call and pass parameter the function process and run
Pyhton code:
import pandas as pd
data_xls = pd.read_excel('/demo/ab/excelfile.xlsx', 'Sheet1', dtype=str, index_col=None)
data_xls.to_csv('csvfile.csv', encoding='utf-8', index=False)
I need like below:
def pyconv(function):
var=path
fname=filename
import pandas as pd
data_xls = pd.read_excel('var', 'fname', dtype=str, index_col=None)
data_xls.to_csv('csvfile.csv', encoding='utf-8', index=False)
when i call function and pass parameter it should run:
pycon(path,filename)
my function will take var value: '/demo/ab/excelfile.xlsx' and fname=sheet1
pycon('/demo/ab/excelfile.xlsx','sheet1')
def pycon(path,sheet):
import pandas as pd
data_xls = pd.read_excel(path,sheet, dtype=str, index_col=None)
data_xls.to_csv('csvfile.csv', encoding='utf-8', index=False)
and now this shall work
pycon(r'/demo/ab/excelfile.xlsx','sheet1')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.