14、表格显示控制
In [ ]:
'''
表格显示控制
df.style.format()
只是更改了显示样式
原数据不会更改
'''
In [1]:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline
In [2]:
df = pd.DataFrame(np.random.randn(10,4),columns=['a','b','c','d'])
sty = df.style
In [3]:
# 按照百分数显示
df = pd.DataFrame(np.random.randn(10,4),columns=['a','b','c','d'])
print(df.head())
df.head().style.format("{:.2%}")
Out[3]:
In [4]:
# 显示小数点数
df.head().style.format("{:.4f}")
Out[4]:
In [5]:
# 显示正负数
df.head().style.format("{:+.2f}")
Out[5]:
In [6]:
# 分列显示
df.head().style.format({'b':"{:.2%}", 'c':"{:+.3f}", 'd':"{:.3f}"})
Out[6]:
In [ ]:

浙公网安备 33010602011771号