I am writing a class containing pandas functionalities. As an input I have a pandas dataframe but python seems to not recognizing it right.
import pandas as pd
class box:
def __init__(self, dataFrame, pers, limit):
self.df = dataFrame,
self.pers = pers,
self.data = limit
def cleanDataset(self):
persDf = self.df.filter(regex=('^' + self.pers + r'[1-9]$'))
persDF.replace({'-': None})
self.df.filter(...) gives me the warning: Instance of 'tuple' has no 'filter' member
. I have found this but cannot apply the solution though since the problem is not caused by django.
Anyone who can help me out here?
Your problem is the comma at the end of
self.df = dataFrame,
(andself.pers = pers,
). The comma isn't necessary here.The comma makes the class think you're defining
self.df
as a tuple with one member. To check this, create a box objectb
and tryprint type(box.df)
. I'm guessing this will return<type 'tuple'>
.Remove the commas after the attribute definitions: