Home > OS >  extract from pandas dataframe into new dataframe
extract from pandas dataframe into new dataframe

Time:07-30

so lets say i have a pandas dataframe which has three columns, Account Number, Date, and Volume.

i want to be able to create a new dataframe with the same columns but filtered by a prompt i chose (in this case 2022-08-17) and all accounts.

in reality the sheet is much larger and has alot of accounts.

see example below:

enter image description here

thank you

CodePudding user response:

IIUC, you need:

(df[df['Prompt'].eq('2022-08-17')]
.groupby(['Account', 'Prompt'], as_index=False)
.sum()
)

Output:

No output provided as the input format was an image

  • Related