title: How do I do a time series analysis as part of running a function in Python 3.7?
body: <p>I have this:</p>
  <p>formulas_count_stats.py:</p>
  <pre><code>import pandas as pd
  from df_count_stats import df, df1
  
  df = df
  df1 = df1
  
  class Data_load_compare_0:
      def __init__(self, df):
          self.df = pd.read_csv(df, delimiter=';')
  
          '''
          Data information section from df  = basic stats
  
          '''
  
      def get_EDA_columns(self):
          return self.df.columns
  
      def get_EDA_info(self):
          return self.df.info()
  
      def get_EDA_describe(self):
          return self.df.describe()
  
      def get_EDA_shape(self):
          return self.df.shape
  
      def get_EDA_value_counts(self):
          return self.df.value_counts()
  
      def get_EDA_isnull(self):
          return self.df.isnull()
  
      def get_EDA_dtypes(self):
          return self.df.dtypes
  
      def get_EDA_isna(self):
          return self.df.isna()
  
      def get_EDA_nunique(self):
          return self.df.nunique()
  
      def get_EDA_sort_dipl(self):
          return self.df.query(&quot;col1 == 'X'&quot;)
  
      def get_EDA_sort_bach(self):
          return self.df.query(&quot;col1 == 'Y'&quot;)
  
      def get_EDA_sort_by_line(self):
          return self.df.groupby(['col2', 'col1', 'col3']).agg(['count'])# groupby(['User Name', 'col2'])['col1'].size().reset_index(name='counts')
  
      '''
      Time series
      '''
      import matplotlib.pyplot as plt
      def get_time_series(self):
          df['Logon Time'] = pd.to_datetime(df['Logon Time'], errors='coerce')
          df['Year'] = df.index.dt.year
          df['month'] = df.index.dt.month
          df['day'] = df.inde.dt.day
          df['hour'] = df.index.dt.hour
          df['week'] = df.index.dt.week
          df['count'] = df['User Name']
          return df.groupby([df['Logon Time'].dt.year, df['Logon Time'].dt.month]).sum().plot.bar()
      plt.show()
  </code></pre>
  <p>...and running the functions from main_count_stats.py (loading data from df_count_stats.py):</p>
  <pre><code>from df_count_stats import df_load, df1_load
  from formulas_count_stats import Data_load_compare_0, Data_load_compare_1
  
  myData = Data_load_compare_0(df_load)
  myData1 = Data_load_compare_1(df1_load)
  
  EDA_stats_00_0 = myData.get_EDA_columns()
  EDA_stats_01_0 = myData.get_EDA_nunique()
  EDA_stats_02_0 = myData.get_EDA_shape()
  EDA_stats_03_0 = myData.get_EDA_info()
  EDA_stats_04_0 = myData.get_EDA_isna()
  EDA_stats_05_0 = myData.get_EDA_isnull()
  EDA_stats_06_0 = myData.get_EDA_describe()
  EDA_stats_07_0 = myData.get_EDA_dtypes()
  EDA_stats_08_0 = myData.get_EDA_sort_bach()
  EDA_stats_09_0 = myData.get_EDA_sort_dipl()
  EDA_stats_10_0 = myData.get_EDA_sort_by_line()
  EDA_stats_11_0 = myData.get_time_series()
  </code></pre>
  <p>I get this error:</p>
  <pre class="lang-none prettyprint-override"><code>Traceback (most recent call last):
    File &quot;C:/.../.../main_count_stats.py&quot;, line 25, in &lt;module&gt;
      EDA_stats_11_0 = myData.get_time_series()
    File &quot;C:\...\...\...\formulas_count_stats.py&quot;, line 59, in get_time_series
      df['Year'] = df.index.dt.year
  AttributeError: 'RangeIndex' object has no attribute 'dt'
  </code></pre>
  <p>I hoped that my attempt to integrate a simple time series analysis as part of an otherwise well-functioning formulas_count_stats.py would work. Obviously, it does not. I did change the index to a 'to_datetime' format.</p>
  <p>How can I solve this?</p>