Why do I keep getting KeyError: ‘Credits’ for this code:
# Assuming dmtm_tsr is the DataFrame
# Pivot table code
pivot_summary = dmtm_tsr.pivot_table(values = ['Credits', 'Message', 'Client Reference No.', 'Client Tags'],index = ['Reinstatement Type', 'Name', 'Email Address', 'Mobile'], aggfunc={'Credits': 'sum', 'Message': 'first', 'Client Reference No.': 'first', 'Client Tags': 'first'}).reset_index()
condition = (pivot_summary['Reinstatement Type'].isin(['AUTO REINSTATEMENT', 'REG REINSTATEMENT', 'REGULAR REINSTATEMENT', 'SPECIAL CON REINSTATEMENT']) &
(pivot_summary['Credits'] == 300) &
(pivot_summary.groupby('Reinstatement Type')['Credits'].transform('sum') >= 350))
Please… I’ve tried re-indexing it or putting it in a column. I don’t think there’s anything wrong with my code, even gpt said so.
New contributor
Christian Lagrana is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.