Python数据分析实战【第三章】3.15-Matplotlib表格样式调用【python】

1.定位空值

df = pd.DataFrame(np.random.rand(5,4),columns = list('ABCD'))
df['A'][2] = np.nan
df.style.highlight_null(null_color='red')

Python数据分析实战【第三章】3.15-Matplotlib表格样式调用【python】_第1张图片
Python数据分析实战【第三章】3.15-Matplotlib表格样式调用【python】_第2张图片

2.色彩映射


df = pd.DataFrame(np.random.rand(10,4),columns = list('ABCD'))
df.style.background_gradient(cmap='Greens',axis =1,low=0,high=1)
# cmap:颜色
# axis:映射参考,0为行,1以列

Python数据分析实战【第三章】3.15-Matplotlib表格样式调用【python】_第3张图片

3.条形图

df = pd.DataFrame(np.random.rand(10,4),columns = list('ABCD'))
df.style.bar(subset=['A', 'B'], color='#d65f5f', width=100)
# width:最长长度在格子的占比

Python数据分析实战【第三章】3.15-Matplotlib表格样式调用【python】_第4张图片

4.分段式构建样式


df = pd.DataFrame(np.random.rand(10,4),columns = list('ABCD'))
df['A'][[3,2]] = np.nan
df.style.\
    bar(subset=['A', 'B'], color='#d65f5f', width=100).\
    highlight_null(null_color='yellow')

Python数据分析实战【第三章】3.15-Matplotlib表格样式调用【python】_第5张图片

你可能感兴趣的:(Python数据分析实战)