complex pivot in Python

I have a large set of data. What I did in Python is: I apply the filter first Then create a pivot

However when I check the result, it seems like Python did not perform the data filters. Python only did the pivot table.

Please advise

bonds[(bonds['Checkpoint'] == 1) 
      & (bonds['Volcker Desk'] != "FX CASH")
     & (bonds['Volcker Desk'] != "NMRC")]

bonds=pd.pivot_table(
    bonds,
    index=['rating'],
    columns=['Bond Type'],
    values=['Holding Amt 1'],
    aggfunc='sum'
)

bonds

Answer

You are filtering the data and not using/assigning it to another variable

bonds_filtered = bonds[(bonds['Checkpoint'] == 1) 
    & (bonds['Volcker Desk'] != "FX CASH")
    & (bonds['Volcker Desk'] != "NMRC")]

bonds_pivot=pd.pivot_table(
    bonds_filtered ,
    index=['rating'],
    columns=['Bond Type'],
    values=['Holding Amt 1'],
    aggfunc='sum'
)

if you don’t want to introduce new variables you can rename everything to bonds. Just don’t forget to assign it