0
votes

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
Have you tried adapting the examples you can find in the pandas documentation?Mr. T

1 Answers

1
votes

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