correctly plotting datetime64[ns] to graph

Running into a issue here. See data snapshot below:

Dates:

NKE   2019-02-28
NKE   2019-05-31
NKE   2019-08-31
NKE   2019-11-30
NKE   2020-02-29 
Name: asOfDate, dtype: datetime64[ns] symbol

Values:

 NKE   852000000.00 
 NKE   1737000000.00
 NKE   2023000000.00
 NKE   674000000.00 
 NKE   2165500000.00
Name: FreeCashFlow, dtype: float64 symbol

Basically if i were to plot the dates and the values into a bar graph. The value is out of sync with the dates. I’ve bursting my brains trying to figure this out for the past two hours. Any help will be greatly appreciated.

For example: enter image description here

See code below:

import matplotlib
from yahooquery import Ticker
import pandas as pd
import matplotlib.pyplot as plt
from pandas.plotting import register_matplotlib_converters

fig, ax = plt.subplots()

Tickers = Ticker('NKE')

cashFlowData = Tickers.cash_flow(frequency='q')

 ax.set_title('Cash Flow Chart')
 ax.set_xlabel('Years')
 ax.set_ylabel('Cash Amount')


 register_matplotlib_converters()

 plt.bar(cashFlowData["asOfDate"],cashFlowData["FreeCashFlow"])
 ax.get_yaxis().set_major_formatter(matplotlib.ticker.FuncFormatter(lambda x, p: format(int(x), ',')))
 plt.show()

Answer

Your question is not clear, so it’s tough to figure out exactly what you are looking for, but if you are trying to just show the days for the purpose of showing a chart, then you can add the following line of code:

cashFlowData['asOfDate']=cashFlowData['asOfDate'].astype(str)

Full code:

import matplotlib
from yahooquery import Ticker
import pandas as pd
import matplotlib.pyplot as plt
from pandas.plotting import register_matplotlib_converters

fig, ax = plt.subplots()

Tickers = Ticker('NKE')

cashFlowData = Tickers.cash_flow(frequency='q')
# cashFlowData = cashFlowData[['asOfDate', 'FreeCashFlow']]
cashFlowData['asOfDate']=cashFlowData['asOfDate'].astype(str)

ax.set_title('Cash Flow Chart')
ax.set_xlabel('Years')
ax.set_ylabel('Cash Amount')


register_matplotlib_converters()

plt.bar(cashFlowData["asOfDate"],cashFlowData["FreeCashFlow"])
ax.get_yaxis().set_major_formatter(matplotlib.ticker.FuncFormatter(lambda x, p: format(int(x), ',')))
plt.show()

By Day for relevant days