Manipulating DataFrame with custom dataclass methods
Solution 1:
you can first get an instance x
of the class Data
.
x = Data()
# Attempt 1
new_data1 = x.clean(my_data1) # Parameter "ser" unfilled
# Attempt 2
new_data1 = x.clean(ser=my_data1) # Parameter "self" unfilled
If I were you I would not use a class this way, I would instead just define the following function
def clean(ser):
acceptcols = np.where(ser.loc[0, :] == '2')[0]
data = ser.iloc[:, np.insert(acceptcols, 0, 0)]
data = ser.drop(0)
data = ser.rename(columns={'': 'Time(s)'})
data = ser.astype(float)
data = ser.reset_index(drop=True)
data.columns = [column.replace('1', '')
for column in ser.columns]
return data
and call it directly.
Also, in your clean()
, each modification is based on ser
which is the input, but not the last modification. This is a problem, isn't this?