我已经清理了我的数据集,并在不同的数据帧中分离了代码块。这些数据帧被放入一个列表中。就个人而言,它工作得很好,但在循环中,我没有得到任何输出
def trialflag(x):
default=''
green='background-color: green'
blue='background-color: blue'
yellow='background-color: yellow'
orange='background-color: orange'
red='background-color: red'
g= x['THI Flag'] == "Green"
b= x['THI Flag'] == "Blue"
y= x['THI Flag'] == "Yellow"
o= x['THI Flag'] == "Orange"
r= x['THI Flag'] == "Red"
df1 = pd.DataFrame(default, index=x.index, columns=x.columns)
df1.loc[g, ['THI','THI Flag']] = green
df1.loc[b,['THI','THI Flag']]= blue
df1.loc[y, ['THI','THI Flag']] = yellow
df1.loc[o,['THI','THI Flag']] = orange
df1.loc[r,['THI','THI Flag']] = red
return df1
for i in range(0,ntrans):
(transformerlist[I].head(5))[['Meter_Serial_Number','THI','THI Flag','THI Action']].style.apply(trialflag,axis=None)
输出:(我什么也得不到)
对于此示例:
def trialflag(x):
default=''
green='background-color: green'
blue='background-color: blue'
yellow='background-color: yellow'
orange='background-color: orange'
red='background-color: red'
g= x['THI Flag'] == "Green"
b= x['THI Flag'] == "Blue"
y= x['THI Flag'] == "Yellow"
o= x['THI Flag'] == "Orange"
r= x['THI Flag'] == "Red"
df1 = pd.DataFrame(default, index=x.index, columns=x.columns)
df1.loc[g, ['THI','THI Flag']] = green
df1.loc[b,['THI','THI Flag']]= blue
df1.loc[y, ['THI','THI Flag']] = yellow
df1.loc[o,['THI','THI Flag']] = orange
df1.loc[r,['THI','THI Flag']] = red
return df1
transdup=transformerlist[0]
transformerlist[0].head(5)[['Meter_Serial_Number','THI','THI Flag']].style.apply(trialflag,axis=None)
我试图得到一个输出,它显示transformerlist中每个数据帧的样式。如有任何想法和建议,将不胜感激
您需要在循环中调用
display
相关问题 更多 >
编程相关推荐