0

Can someone help me with my problem because I am newby to pandas and I have been confused.

Initially I made some subset selections and everything OK with my new dataframe(which is type pandas.core.frame.DataFrame). My new dataframe has two columns (date, count) and I want to plot a line plot having the date at the x axis and the count on y axis.

Suppose the name of the data frame is df and the names of the columns are date and count according to pandas documentation the command is:

ts = pd.Series(df['count'], index = df['date'])
ts.plot()

where is the wrong?

any help

1
  • 1
    Have you tried adapting the examples you can find in the pandas documentation? Commented Nov 24, 2018 at 9:42

1 Answer 1

1

It's best to refer Pandas website for first hand information. However, you can try the below code out-

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt # For show command

# Creating a dummy dataframe (You can also go ahead with Series)
df = pd.DataFrame([45, 20], columns=['count'], index=['12/11/2018', '10/1/2018'])

# Converting string to datetime format
df.index = pd.to_datetime(df.index, format='%d/%m/%Y')
df.index 
# DatetimeIndex(['2018-11-12', '2018-01-10'], dtype='datetime64[ns]', freq=None)

df.plot()
plt.show()

Pandas plot

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

1 Comment

@Er1Hall if you find the answer useful, do accept it. If there's still some confusion, just comment.

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.