0

Im very new to python and trying to figure out how to graph out some data which can have missing data for any given date.

The data is number of jobs completed (y), their rating (secondary Y), and date (x).

The graph looks how id like however jobs dont get completed each day so there are days where there is no data and the line on the graph just stops.

Is there a way to have it automatically connect the dots on the graph?

import matplotlib.pyplot as plt
import pandas as pd
import database


df = pd.DataFrame(database.getTasks("Pete"), columns=['date', 'rating', 'jobs']).set_index('date')

fig, ax = plt.subplots()
ax3 = ax.twinx()
rspine = ax3.spines['right']
rspine.set_position(('axes', 1.15))
ax3.set_frame_on(True)
ax3.patch.set_visible(False)

df.jobs.plot(ax=ax, style='b-')
df.rating.plot(ax=ax, style='r-', secondary_y=True)

plt.show()
2
  • 1
    looks like your database has entries for every day, while not every day has jobs, hence jobs/ratings values. To deal with this issue, you can either fill in placeholder values for the dates with no values through df.fillna(arguments) or drop the values df.dropna(inplace=True). If there are no non-observation data, it will connect the dots. Commented Mar 19, 2021 at 9:47
  • fillna didnt make any difference but the df.dropna(inplace=True) seems to worked perfectly. thankyou so much! :) Commented Mar 20, 2021 at 9:45

2 Answers 2

3

I think you are looking for Dataframe.fillna().

df.fillna(method='ffill')

Forward Fill ('ffill') will use the last valid observation in place of a missing value.

Sign up to request clarification or add additional context in comments.

Comments

0

to fill your data you can use pandas fill.na and use 'method=ffill' to propagate the last valid value. Check the documentation to see what method fits best.

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.