答案 0 :(得分:1)
尝试一下:
from numpy.random import randint
import pandas as pd
import matplotlib.pyplot as plt
df1=pd.DataFrame([[1,2,3,4,5,6,7,8,9,10,11],list(randint(400,500,11)),randint(400,500,11)]).T
df1.columns=['CustomerS','value1','value2']
#df1=df1.set_index('CustomerS')
df2=pd.DataFrame([[1,2,3,4,5,6,7,8,9,10,11],randint(0,10,11)]).T
df2.columns=['CustomerS','value1']
#df2=df2.set_index('CustomerS')
df3 = df1.merge(df2,on='CustomerS') #merging two dataframes
df3.columns = ['CustomerS','value1','value2','value3']
df3.iloc[:,:-1].plot.bar(x='CustomerS',stacked=True)
df3.iloc[:,-1].plot(x='CustomerS',secondary_y=True, color='r')
plt.legend(loc=2)