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?
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.
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.
Try this,
monthly_mean.plot(y='A', use_index=True)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With