DataSource.py(使用jupyter notebook創建,另存為py的)
import os
import pandas as pd
def GetExcel(fullName,sheetName):
if os.path.exists(fullName) and os.path.isfile(fullName):
xls = pd.ExcelFile(fullName) #打開excel檔案
sheettab = xls.parse(sheetName) #打開指定sheet頁
xls.close #關閉excel檔案
return sheettab
else:
print('檔案'+fullName+'不存在')
======================================================
另外一個notebook中的代碼
import pandas as pd
import seaborn as sns
import DataSource as DS #此處運行正確
file='./index/files/專案推介方案.xlsx'
price = pd.DataFrame(DS.GetExcel(file,'外包人力價格'))
print(type(price)
newcolname = {'專家級':'level','整年包(萬)':'dprice'} #設定一個新舊名稱的映射字典
price.rename(columns=newcolname,inplace=True) #欄位重命名
#print('B',price.shape)
price = price.dropna(subset=['level','dprice'],how='any') #洗掉指定欄位為空的所有行
#print('A',price.shape)
================================
問題:這兩段代碼放在一個notebook中執行沒有問題,但分拆開后,price = pd.DataFrame(DS.GetExcel(file,'外包人力價格'))拿不到函式的回傳值
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/253648.html
