python實現excel 的lookup函式

2021-10-06 23:47:00 字數 706 閱讀 9263

sx_customer_0409=pd.read_excel(r'e:\lll\\sx_customer_0409.xlsx'

)#讀取資料

fx_variable=pd.read_excel(r'e:\lll\202004\\fx_variable.xlsx'

)#讀取分箱列表

'''定義lookup函式'''

deflookup

(lookup_value,lookup_vector,return_vector)

:"""

與excel中的lookup函式一樣

"""return return_vector[lookup_value >= lookup_vector]

.tolist()[

-1]'''遍歷資料表的變數執行lookup函式'''

for i in variable:

sx_customer[i]

= sx_customer[i]

.(lookup,args=

(fx_variable[fx_variable[

'變數'

]==i]

['下限'

],fx_variable[fx_variable[

'變數'

]==i]

['分值'])

)#args給自定義函式第一引數以為的引數賦值

l建立Excel檔案

最近的專案中遇到需要將list 儲存到excel檔案中,為滿足此需求設計實現了如下函式 1 2 將maplist轉化為excel檔案3 param excelfile excel檔案的路徑4 param maplist 要儲存的maplist5 param titles 對應的列名稱6 param ...

Python實現Excel隨機抽取數

有這樣一組資料 現在要隨機抽取十個數字,如下 import sys import xlrd import random print pm2.5 天津 開啟excel workbook xlrd.open workbook 2.xls 進入sheet excel sheet workbook.shee...

python實現excel資料匯入mysql

excel資料格式 總行數 len df nums df.shape 0 資料清洗nan預設為0 df.fillna 0,inplace true 刪除第一行無用資料 ds df.drop index 0,0 nums nums 1 資料庫操作 class mysqlact object def i...