1 format
1.0 数据
# Visual Python: Data Analysis > File
vp_df = pd.read_csv('https://raw.githubusercontent.com/visualpython/visualpython/main/visualpython/data/sample_csv/iris.csv')
vp_df=vp_df[:5]
vp_df.at[0,'sepal_length']=np.nan
vp_df.at[2,'sepal_length']=10000
vp_df
1.1 format
df.style.format(formatter: 'ExtFormatter | None' = None,subset: 'Subset | None' = None,na_rep: 'str | None' = None,precision: 'int | None' = None,decimal: 'str' = '.',thousands: 'str | None' = None,escape: 'str | None' = None,
)
1.1.1 formatter
显示的格式
vp_df.style.format(formatter='{}个',subset=['sepal_length','sepal_width','petal_length','petal_width'])
用字典+
1.1.2 na_rep
指定缺失值的格式
vp_df.style.format(na_rep='W无')
1.1.3 precision
指定浮点位数
1.1.4 decimal
用作浮点数、复数和整数的十进制分隔符的字符
1.1.5 thousands
浮点数、复数和整数的千位分隔符的字符
2 添加标题
vp_df.style.set_caption('iris')
3 隐藏内容
3.1 隐藏索引
vp_df.style.hide(axis='index')
3.2 隐藏某一列
vp_df.style.hide_columns(['sepal_length','sepal_width'])