新增聚合列
zt['借款总次数']=zt.groupby('idcard')['loan_date'].transform('count')
将数据拆分并统计
yxjj['reason_code']=yxjj['reason_code'].apply(lambda x:str(x).split(", "))
def hmd(x):
a=0
for i in x:
if i in ['']:
a=a+1
return a
日期转化
import datetime
now = datetime.datetime.now()
(s,'%Y/%m/%d %H:%M:%S') #先将字符串变成时间,再将时间变为字符串且此时可选择日期格式
将其他类型变成时间类型,不能随意改格式
to_datetime(arg=data['apply_date'],format="%Y-%m-%d")
字符串变时间类型
data['apply_date']=data['apply_date'].apply(lambda x:dt.datetime.strptime(x,"%Y-%m-%d"))
时间类型变字符串
import datetime as dt
data['apply_date']=data['apply_date'].apply(lambda x:dt.datetime.now().strftime('%Y-%m'))
画图
画图,柱状图
import matplotlib.pyplot as plt
import numpy as np
import matplotlib as mpl
y=[10,30,14,15,5,5]
name=['10_20','20_30','30_40','40_50','50_60','60_70']
plt.bar(x,y,tick_label=name,width=3)
plt.ylim((0,35))
for x,y in zip(x,y):
plt.text(x,y,y,ha='center',va='bottom')
点图
import matplotlib.pyplot as plt
import matplotlib as mpl
import matplotlib.pyplot as plt
x=[10,3,1,12,14,5,8,9,14,15,21]
y2=[15,31,2,14,15,6,31,20,25,12,12]
plt.scatter(x,y2)
plt.legend()
plt.show()