3

Issue

Plotting data from a DataFrame into a line plot excludes "dates" on the x axis.

north_result = list(data.aggregate(pipeline))

dates =['Jun','Jul','Aug','Sep','Oct','Nov','Dec','Jan','Feb','Mar','Apr','May']
north_result_df = pd.DataFrame(north_result, index=dates)
north_result_df.index.name = 'Months'
north_result_df.plot.line()

enter image description here

Line plot requires dates just above 'months' on the x axis. Dates show if they are numeric and not strings...any help would be greatly appreciated! As you can tell i am pretty new to Pandas...

Solution

north_result = list(data.aggregate(pipeline))

dates =['Jun','Jul','Aug','Sep','Oct','Nov','Dec','Jan','Feb','Mar','Apr','May']
north_result_df = pd.DataFrame(north_result, index=dates)
north_result_df.index.name = 'Months'
plt.plot(north_result_df.index, north_result_df["total"])
plt.show()
7
  • Which version of pandas? In my 0.24.1 it works and looks as expected. Commented Mar 8, 2019 at 15:23
  • 1
    This issue is still not fixed. Commented Mar 8, 2019 at 18:00
  • Great....anyway around it Ernest? Commented Mar 8, 2019 at 19:24
  • My suggestion would be the same as the answer below: use matplotlib directly instead. Commented Mar 8, 2019 at 19:43
  • 1
    I have no idea what list(data.aggregate(pipeline)) does. But if you have a usual dataframe with numerical values in a column and a normal index (no multiindex, no PeriodIndex) you can use plt.plot(df.index, df["column"]). Commented Mar 8, 2019 at 19:47

1 Answer 1

2

you can use pyplot

import matplotlib.pyplot as plt
north_result =[5,6,7,2,8,5,4,8,9,4,1,5]
dates =['Jun','Jul','Aug','Sep','Oct','Nov','Dec','Jan','Feb','Mar','Apr','May']
north_result_df = pd.DataFrame(north_result, index=dates)
north_result_df.index.name = 'Months'
plt.plot(north_result_df)
plt.show()

the result will be like:

enter image description here

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

2 Comments

Cheers however I now get - TypeError: unhashable type: 'numpy.ndarray' - north_result_df is declared as follows = north_result = list(street.aggregate(pipeline))
Final solution added to question

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.