I am trying to filter a pivot table based on adding filter to pandas pivot table but it doesn't work.
maintenance_part_consumptionDF[(maintenance_part_consumptionDF.Asset == 'A006104') & (maintenance_part_consumptionDF.Reason == 'R565')].pivot_table(
values=["Quantity", "Part"],
index=["Asset"],
columns=["Reason"],
aggfunc={"Quantity": np.sum, "Part": lambda x: len(x.unique())},
fill_value=0,
)
But shows, TypeError: pivot_table() got multiple values for argument 'values'
Update
Creation of the pivot table:
import numpy as np
maintenance_part_consumption_pivottable_part = pd.pivot_table(
maintenance_part_consumptionDF,
values=["Quantity", "Part"],
index=["Asset"],
columns=["Reason"],
aggfunc={"Quantity": np.sum, "Part": lambda x: len(x.unique())},
fill_value=0,
)
maintenance_part_consumption_pivottable_part.head(2)
When I slice it manually:
maintenance_part_consumption_pivottable_partDF=pd.DataFrame(maintenance_part_consumption_pivottable_part)
maintenance_part_consumption_pivottable_partDF.iloc[15,[8]]
I get this output:
Reason Part R565 38 Name: A006104, dtype: int64
Which is the exact output I need. But I don't want to do this way with iloc because it's more mechanical I have to count the number of y row indexes or/and x row indexes before getting to the result "38".
Hint: If I could take the asset description itsel and also for the reason from the table like it's asked on the question below.
How many unique parts were used for the asset A006104 for the failure reason R565?
Sorry, I wanted to upload the table via an image to make it more realistic but I am not allowed.