I have the following code and it works but all of a sudden returns an value error without any change in code.
My code
filtered_data = pivoted_data[(pivoted_data['MoM']<-10000) | (pivoted_data['MoM']>10000)]
#sort filtered data by largest values
new_df = new_df.sort_values(by=('MoM'), ascending=False)
The dataframe looks like this:
Total Amount | Total Amount | Total Amount | MoM | |
---|---|---|---|---|
Period | Jan | Feb | Mar | |
Name | ||||
Client A | 500 | 7000 | 14000 | +7000 |
Client B | 500 | 70000 | 14000 | -56000 |
Client C | 500 | 70000 | 80000 | +10000 |
And this is how is should look after the code to filter and sort:
Total Amount | MoM | |||
---|---|---|---|---|
Period | Jan | Feb | Mar | |
Name | ||||
Client B | 500 | 70000 | 14000 | -56000 |
Client C | 500 | 70000 | 80000 | +10000 |
However I get the following error:
ValueError: The column label 'MoM' is not unique.
For a multi-index, the label must be a tuple with elements corresponding to each level.
I also get the following error:
Expected type: (<class 'tuple'>, <class 'list'>)
Received value of type <class 'NoneType'>:
None
In terms of tuples I’ve tried doing
new_df = new_df.sort_values(by='MoM', '', '' , ascending=False)
as I’m aware there’s two blanks beneath MoM & I’ve tried new_df = new_df.sort_values(by='MoM','Period', '', ascending=False)
but then it raises keyerrors.
Appreciate the help!