Search code examples
pythonpandasplotlyplotly-python

Plotly base values are in percentage


I have table in which one my base values are in percentage

ID     TYPE     PERCENTAGE
1      gold         15%
2      silver       71.4%
3      platinum     20%  
4      copper       88.88%

But plotly doesn't like that

enter image description here

Do you know how I could tell him "hey these data are in percentage, please show me a percentage graph"?


Solution

  • I think plotly is the required answer, so I created it in Plotly. I have converted the percentages in the existing data frame to decimal format. Finally, I set the Y axis display to '%'.

    import plotly.express as px
    
    df['PERCENTAGE'] = df['PERCENTAGE'].apply(lambda x:float(str(x).strip('%')) / 100)
    
    fig = px.bar(df, x='TYPE', y='PERCENTAGE')
    fig.update_layout(yaxis_tickformat='%')
    fig.show()
    

    enter image description here