DataFrame-category

PHOTO EMBED

Fri Apr 08 2022 14:33:48 GMT+0000 (UTC)

Saved by @vivienfeng11

cats=["Usage_gross","Mileage_gross","Late_return_gross","Driving_credits_gross","PCN_gross","PCN_admin_gross","Flex_gross","Total_VAT"]
cat_type+=+CategoricalDtype(categories=cats,+ordered=True)
tran_data['charge_type']+=+tran_data['charge_type'].astype(cat_type)

df_pivot+=+tran_data.pivot_table(index=['reservation_id'],values=["amount"],columns=['charge_type'],aggfunc=np.sum).fillna(0)

df_pivot.columns+=+df_pivot.columns.droplevel(0)

flattened+=+pd.DataFrame(df_pivot.to_records())+#+convert+pivot+table+to+dataframe
content_copyCOPY

undefined