0 votes
1 view
in Data Science by (17.6k points)

I have two catogery column the values in first are client_abc, client_def, the second column are F1,F2,F3 and rest are the numeric column.

data looks like

 date       client          facility     count     claim

21/3/2019   'client_abc'     F1           200        1300

22/3/2019    'client_def'    F2           400        1800

21/3/2019    'client_abc'    F3           1000       3000

22/3/2019    'client_def'    F1           380        3600

21/3/2019    'client_abc'    F2           900        900

22/3/2019    'client_def'    F3           1030       2500

21/3/2019    'client_abc'    F1           190        1700

22/3/2019    'client_def'    F2           100000     1560

for client 'abc' and 'f1'

 date       client          facility     count     claim

21/3/2019   'client_abc'     F1           200        1300

21/3/2019    'client_abc'    F1           190        1700

similarly for 'abc' and 'f2' ,'abc' and 'f3', 'def' and 'f1','def' and 'f2','def' and 'f3'.

My attempt

df_fac_f1 =df[facility=='F1' & client == 'client_abc' ]

df_fac_f1 =df[facility=='F1' & client == 'client_def' ]

df_fac_f1 =df[facility=='F2' & client == 'client_abc' ]

df_fac_f1 =df[facility=='F2' & client == 'client_def' ]

df_fac_f1 =df[facility=='F3' & client == 'client_abc' ]

df_fac_f1 =df[facility=='F3' & client == 'client_def' ]

How ca I get the same result without knowing the facility and client column values in advance?

1 Answer

0 votes
by (41.4k points)

Use the below code:

grouped = df.groupby(['client','facility'])

print(grouped.get_group(('client_abc', 'F1')))

Output will be:

         date      client facility  count

 0  21/3/2019  client_abc       F1    200

 2  21/3/2019  client_abc       F1   1000

 4  21/3/2019  client_abc       F1    900

 6  21/3/2019  client_abc       F1    190

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...