1
votes

I have pandas pivot table datafrme "df_summary_table". print(df_summary_table) gives [16 rows x 21 columns]

    m1 = (df_summary_table.index == "test1")
    m2 = df_summary_table.columns.str.startswith('NA')
    df_summary_table.loc[m1 & m2] = 10

I am trying to perfoem above operation getting weired error. print(m1) gives:

[ True False False False False False False False False False False False
 False False False False]

length of m1 is 16 print(m2) gives :

    [False False False False False False False False False False  True  True
  True  True  True  True  True  True  True  True False]

length of m2 is 21

both m1 and m2 are "" Can anyone help me to solve this issue?

1

1 Answers

0
votes

Problem is there is no Multiindex, so need m1 for filter rows and m2 for filter columns, "cost" has to be removed and mask cannot be chained by &, because different lengths and different filtering (first filter per rows, second per columns):

df_summary_table.loc[m1, m2] = 10