0

I'm having a problem with something I've done many times before and I'm just not seeing what is going wrong. I have a dataframe with two column - Date and Results. I want to plot the Daate along the X axis and the results along the Y axis. The dataframe is in date order. I have tried with date as the index, and just sorted. But instead of the Y axis being a range from low to high, it is showing the actual result instead. Here is an example: enter image description here

The x-axis is jumping around instead of the bars. The code couldn't be any simpler:

def results_chart(df):

    fig, ax = plt.subplots()

    ax.set_xlabel('Date', fontsize=10)
    ax.set_ylabel('Result', fontsize=12)
    ax.set_title("Results")

    ax.bar(df["Date"], df["Result"])
    plt.tight_layout()
    graph = get_graph()

    return graph

I must be missing something very basic. Help appreciated,

1
  • 4
    what's the output of print(df['Result'].dtype) Commented Mar 6, 2022 at 21:42

1 Answer 1

2

It seems that the values in df['Result'] are strings. You will need to convert them to a float.

df['Result'] = df['Result'].astype(float)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.