!/usr/bin/env python
coding: utf-8
In[63]:
import pandas as pd
import numpy as np
import pymysql
conn=pymysql.connect(host="10.101.2.32",user="chenqianguang",passwd="select20",db='clx_loan')
sql=''''''
yx=pd.read_sql_query(sql,conn)
yx
In[65]:
import pymysql
import pandas as pd
from sqlalchemy import create_engine
conn = pymysql.connect(host='10.101.2.41',user = "select_fk",passwd = "select_fk#2022", db = "chenqianguang")
讀取資料
建立連線,username替換為使用者名稱,passwd替換為密碼,test替換為資料庫名
conn = create_engine('mysql+pymysql://select_fk:select_fk#2022@10.101.2.41:3306/chenqianguang',encoding='utf8')
寫入資料,table_name為表名,‘replace’表示如果同名表存在就替換掉
yx.to_sql("dpt50", conn, if_exists='replace', index=False)
In[ ]:
In[ ]:
In[ ]:
In[66]:
import pandas as pd
import numpy as np
df2=pd.DataFrame({'typle1':[2,3,4,4,4,4,4],'month1':[9,3,5,5,6,5,6],
"amount1":[3,5,5,5,6,np.nan,6]})
df2
In[50]:
df2['合計']=df2.iloc[:,:].sum(axis=1)
for i in df2.columns[:]:
df2[i] = df2[i]/df2['合計']
df2
In[55]:
df2.loc['Row_sum'] = df2.iloc[:,:].apply(lambda x: x.sum())
tmp1=df2.iloc[:-1,:]/df2.iloc[:-1,:].sum()
tmp1
In[ ]:
HX1['本月-訓練集']=HX1['本月-訓練集'].apply(lambda x:format(x,'.2%'))
In[59]:
import pandas as pd
import numpy as np
fj=pd.DataFrame({'product_name':['A','B','C'],'平均復借次數':[9,3,5],
"復借率":[3,5,5]})
fj
In[60]:
fjs=fj
fjs=pd.DataFrame(fj)
fjs=fjs[['product_name','平均復借次數','復借率']].T
import numpy as np
array = np.array(fjs)
list = array.tolist()
list = list[0]
fjs.columns = list
fjs.drop("product_name", inplace=True)
fjs['中文名']=fjs.index
In[67]:
df2
In[ ]:
def qj(x):
values=[0,1,2,5,8,10,15,20,30,50,100,np.inf]
index=['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R']
for i in range(len(values)-1):
if values[i]<=x<values[i+1]:
return '{0}_[{1},{2})'.format(index[i],values[i],values[i+1])
return '空值'
BH['近6個月履約貸款次數']=BH['近6個月履約貸款次數'].astype('float')
BH['近6個月履約貸款次數']=BH['近6個月履約貸款次數'].apply(qj)
In[ ]:
python: 3.9.7
sklearn: 0.24.2
sklearn2pmml: 0.90.4
joblib: 1.1.0
sklearn_pandas: 2.2.0
pandas: 1.3.4
numpy: 1.20.3
java: 11.0.11
In[ ]:
In[ ]:
In[ ]:
In[ ]:
傳送自 Windows 10 版郵件應用