Python 使用colormap根据一列中的值为整行着色

Python 使用colormap根据一列中的值为整行着色,python,pandas,Python,Pandas,我有一个DataFrame,希望根据一列中的值为整行着色。我可以为一列着色,但在使用颜色贴图时如何为整行着色 import pandas as pd df = pd.DataFrame({'A':[2,5,10], 'B':[7,1,3],}) # define style df.style.background_gradient(cmap='viridis', axis=0, subset='B') 输出: 期望输出

我有一个DataFrame,希望根据一列中的值为整行着色。我可以为一列着色,但在使用颜色贴图时如何为整行着色

import pandas as pd
df =  pd.DataFrame({'A':[2,5,10], 'B':[7,1,3],})

# define style
df.style.background_gradient(cmap='viridis', axis=0, subset='B')
输出:

期望输出