I tried to put some basic preprocessing operations of a pandas dataframe into a seperate class:
import pandas as pd
import numpy as np
from numba import jit
class MyClass:
def _init_(self):
pass
@jit
def preprocess_dataframe(self, path):
self.df = pd.read_csv(path, index_col=False, delimiter=' ' , names=['Time', 'Downloads', 'ServerID', 'Server', 'Date'], usecols=['Time', 'Downloads', 'Server', 'Date'])
print(self.df.head(5))
self.df['Date'] = self.df['Date'].astype(str)
self.df['Timestamp'] = pd.to_datetime(self.df['Time'] +' '+ self.df['Date'], format='%H:%M:%S %Y%m%d')
self.df[['Server_alone', 'Instance']] = self.df['Server'].str.split('-' ,expand=True)
self.df.drop(columns=['Time'], inplace=True)
self.df['Date'] = pd.to_datetime(self.df['Date'], format='%Y-%m-%d')
self.df.set_index(self.df['Date'])
return self.df
When I call this function in my main script (see below) I receive the error:
AttributeError: module 'MyClass' has no attribute 'preprocess_dataframe'
This is the relevant part of my main script:
import MyClass as mc
path = 'Data.txt'
df = mc.preprocess_dataframe(path)
>>>AttributeError: module 'MyClass' has no attribute 'preprocess_dataframe'
I looked up several other questions including this. However, nothing solved my issue despite I think that the fix is quite easy. Thank you for your help!