I am not too far into python yet and here is the case. i got stuck trying to import a function from a class in another file. Here is my code:
import pandas as pd
from sklearn.model_selection import train_test_split
class Prep:
def __init__(self, data):
self.data = data
def slicing(self):
sliceInput = self.data.iloc[:, 1:8]
sliceTarget = self.data.iloc[:, 8]
return sliceInput, sliceTarget
def converting(self):
sliceInput, sliceTarget = self.slicing()
convertInput = sliceInput.to_numpy(float)
convertTarget = sliceTarget.to_numpy(int)
return convertInput, convertTarget
def splitting(self):
convertInput, convertTarget = self.converting()
x = convertInput
y = convertTarget
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.31, random_state=0, shuffle=False)
return x_train, x_test, y_train, y_test
if __name__ == "__main__":
data_frame = pd.read_csv('data_manual.csv', sep=';')
tes = Prep(data_frame)
print(tes.converting())
which works fine.
How do I call or print the splitting(self)
method from example x_train
from another file, example.py in the same directory?
I have tried
from preproces import Prep
a = Prep.splitting()
print(a)
get an error like this TypeError: splitting () missing 1 required positional argument: 'self'
I do not know what happened