一、警告过滤器:
from warnings import simplefilter
simplefilter('ignore')
与之作用相同作用的有:
import warnings
warnings.filterwarnings('ignore')
【ignore - 不会打印匹配的警告】
二、matplotlib绘图
Matplotlib是最流行的python底层绘图库,主要是做数据可视化图表
import matplotlib.pyplot as plt
1、plt.style.use():利用matplotlib绘图设置背景;
2、rc配置:matplotlib使用matplotlibrc [matplotlib resource configurations]配置文件来自定义各种属性,又称rc参数。
e.g. plt.rc("figure", autolayout=True, figsize=(11, 5)) 使子图元素适应画布(自动合理布局) 、图形大小为11*5英寸(宽*高)
e.g. axes:设置坐标轴 --labelweight:轴的字体粗细;labelsize:x轴和y轴标签的字体大小;titlesize:轴标题的大小;titleweight:轴标题粗细;titlepad:标题与图表之间的距离
3、 图形参数:
color=0.75:通过 0-1 范围内的 float 表示灰色程度
markeredgecolor:点的边框色
markerfacecolor:点的填充色
legend:图例
三、seaborn绘图
seaborn是matplotlib库的补充。
import seaborn as sns
① sns.set(context='notebook', style='darkgrid', palette='deep', font='sans-serif', font_scale=1, color_codes=True)
其中,
context = 参数控制着默认的画幅大小,分别有{paper, notebook, talk, poster};
style = 参数控制默认样式,分别有{darkgrid, whitegrid, dark, white, ticks} ;
palette = 参数为预设的调色板,分别有 {deep, muted, bright, pastel, dark, colorblind}等;
font = 用于设置字体;
font_scale = 设置字体大小;
color_codes = True 不使用调色板而采用先前的 ‘r’ 等色彩缩写。
四、函数说明
1、dict():python的内置函数,用于创建一个新的字典(映射)。
e.g.【in】x = dict(name = "Bill", age = 63, country = "USA")
print(x)
【out】 {'name': 'Bill', 'age': 63, 'country': 'USA'}
2、.set_index():使用现有列设置 DataFrame 索引
e.g. store_sales = train.drop('id', axis=1).set_index(['store_nbr', 'family', 'date'])
将训练集中的‘id’列舍弃后,使用'store_nbr'、'family'、'date'三列创建一个新的索引(多层次索引)
3、.unstack():将数据的行index旋转成列columns
五、pandas
1、parse_dates :将某一列设置为时间类型(datetime)
用法详见: https://www.cnblogs.com/pythonzh/p/14182286.html
https://zhuanlan.zhihu.com/p/351056586
infer datetime format = True:大大提升解析速度。
文章介绍了Python中处理警告的过滤器方法,如忽略警告的设置;接着详细讲解了matplotlib库的绘图功能,包括风格设置和图形参数调整;然后提到了seaborn库作为matplotlib的补充,展示了如何设置绘图环境;此外,还讨论了dict()函数创建字典以及pandas中设置DataFrame索引和数据转换的方法,如.set_index()和.unstack()。

被折叠的 条评论
为什么被折叠?



