Count Boolean Variable By Date

Raven

I've been posting a lot lately as I'm new to Python/Pandas. I have a pandas DF called NOTES_TAT_v1. It looks like this:

PT_FIN    Date                Interpreter Needed    Interpreter Used
1        27 January, 2020         1                        1
2        27 January, 2020         1                        0
3        27 January, 2020         0                        0
4        28 January, 2020         0                        0
5        28 January, 2020         1                        1
6        29 January, 2020         1                        0

I'm trying to aggregate the Interpreter columns by Date so the output would look like this:

Date                Interpreter Needed    Interpreter Used
 27 January, 2020         2                        1
 28 January, 2020         1                        1
 29 January, 2020         2                        1

I tried using this code just for the Interpreter Needed column (I ultimately want both Interpreter columns): NOTES_TAT_v2=NOTES_TAT_v1.groupby('Day').Interpreter_Needed.value_counts(). But I'm getting errors Traceback (most recent call last) & DataFrameGroupBy' object has no attribute 'Interpreter_Needed'. Do I need to do a crosstab?

Matthew Borish
import pandas as pd
df = pd.read_csv('df.txt', sep=r"[ ]{2,}")

print(df)

PT_FIN  Date    Interpreter Needed  Interpreter Used
0   1   27 January, 2020    1   1
1   2   27 January, 2020    1   0
2   3   27 January, 2020    0   0
3   4   28 January, 2020    0   0
4   5   28 January, 2020    1   1
5   6   29 January, 2020    1   0

df_gb = df[['Interpreter Needed', 'Interpreter Used']].groupby([df['Date']])

print(df_gb.sum())

        Interpreter Needed  Interpreter Used
Date        
27 January, 2020    2   1
28 January, 2020    1   1
29 January, 2020    1   0

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related