0

I want to use a value from a specific column in my Pandas dataframe as the Y-axis label. The reason for this is that the label could change depending on the Unit of Measure (UoM) - it could be kg, number of bags etc.

#create function using plant and material input to chart planned and actual manufactured quantities

def filter_df(df, plant: str = "", material: str = ""):
    output_df = df.loc[(df['Plant'] == plant) & (df['Material'].str.contains(material))].reset_index()
    return output_df['Planned_Qty_Cumsum'].plot.area (label = 'Planned Quantity'),\
    output_df['Goods_Receipted_Qty_Cumsum'].plot.line(label = 'Delivered Quantity'),\
    plt.title('Planned and Deliverd Quanties'),\
    plt.legend(),\
    plt.xlabel('Number of Process Orders'),\
    plt.ylabel(output_df['UoM (of GR)']),\
    plt.show()

    
#run function
filter_df(df_yield_data_formatted,'*plant*','*material*')

When running the function I get the following error message:

ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

1
  • 2
    The error is caused by the fact that you are passing a pd.Series (i.e. output_df['UoM (of GR)']) to plt.ylabel, while the function is expecting a string, e.g. simply 'UoM (of GR)'.
    – ouroboros1
    Oct 7, 2022 at 13:59

1 Answer 1

0

Yes you can, but the way you are doing you are saying all the values of the Dataframe in that column and you should indicate what row and column you want for the label, use iloc for instace and it will work.

plt.ylabel(df.iloc[2,1])

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.