一、两个list 的对比操作:
①差集
list1.difference(list2)
②交集
list1.intersecttion(list2)
③并集
list1.union(list2)
二、多重索引下提取指定的index或columns
①取index列的索引
第一重索引,data.index.droplevel(1);第二重索引,data.index.droplevel(0)
②取columns的索引
第一重索引,data.columns.droplevel(1);第二重索引,data.columns.droplevel(0)
三、判断列中是否有空值
data[‘colname’].isnull
四、日期频率转换
①日度转换为周度
from datetime import date, datetime, timedelta
#生成今天的日期,并format为"%Y-%m-%d"
today = datetime.strftime(datetime.today(),’%Y-%m-%d’)
#生成时间序列
date_series = pd.date_range(start=‘2017-01-03’, end=today)
#得到年份和周度数的序列
date_series_week = data_series.year.map(str) + “-” + data_series.week.map(str)
五、matplotlib画图
横坐标轴标签函数,set_xticklabels(labels, rotation)
坐标轴字体颜色,xaxis.set_tick_params(labelsize, labelcolor,labelrotation)
图形边框:spines['bottom].set_color(‘none’)
图例:legend(loc=1, edgecolor=‘white’,fontsize)
#图形名称,字体大小
图形标题:set_title(titlename, fontsize)
#解释:图表名称所放位置,高度,左右距离,名字,字体大小,居中显示,字体加粗
图表的名称:fig.text(hight, verhicel, textname, fontsize, ha, weigh=‘bold’)
更详细的介绍请参照
pandas 数据处理https://pandas.pydata.org/pandas-docs/stable/reference/index.html
matplotlib画图https://matplotlib.org/genindex.html