Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use index in pandas to plot data

Tags:

python

pandas

I have a pandas-Dataframe and use resample() to calculate means (e.g. daily or monthly means). Here is a small example.

import pandas as pd   import numpy as np  dates = pd.date_range('1/1/2000', periods=100) df = pd.DataFrame(np.random.randn(100, 1), index=dates, columns=['A'])  monthly_mean = df.resample('M').mean() 

How do I plot the monthly_mean now?

How do I manage to use the index of my new created DataFrame monthly_mean as the x-axis?

like image 953
paulchen Avatar asked Nov 19 '13 23:11

paulchen


People also ask

Can you index a Pandas DataFrame?

Indexing in pandas means simply selecting particular rows and columns of data from a DataFrame. Indexing could mean selecting all the rows and some of the columns, some of the rows and all of the columns, or some of each of the rows and columns. Indexing can also be known as Subset Selection.

How do I turn an index into a column in pandas?

In order to set index to column in pandas DataFrame use reset_index() method. By using this you can also set single, multiple indexes to a column. If you are not aware by default, pandas adds an index to each row of the pandas DataFrame.


1 Answers

Try this,

monthly_mean.plot(y='A', use_index=True) 
like image 167
Pablo Jadzinsky Avatar answered Oct 23 '22 08:10

Pablo Jadzinsky