0

I need to get the value from a column based on two specific column values.

Example Dataframe:

   Charge Code  Billing Number   Date 
0   1250-001      500220        1/2/20
1   1230-002      300220        2/6/20
2   1250-001      500320        3/8/20
3   1225-001      250120        4/9/20
4   1225-002      250120        5/16/20
5   1136-010      361219        12/9/19

I want to get the date for the row that has the charge code 1250-001 and Billing Number 500320 (which would be 3/8/20)

I am attempting to use the following line:

the_date = df_hold.loc[df_hold['Charge Code'] == '1250' & df_hold['Billing Number'] == 500320].index.values

and am receiving the following error:

KeyError: 'the label [1250-001] is not in the [index]'

After using: the_date = df_hold.loc[(df_hold['Charge Code'] == '1250-001') & (df_hold['Billing Number'] == 500320), 'Date']

I got the following:

configure_logger, configure_logger.setup_logger
3    3/8/2020
Name: Invoice Date, dtype: object

is there a way to get the date by itself?

Nick ODell
  • 15,465
  • 3
  • 32
  • 66
codeblue
  • 63
  • 1
  • 8

1 Answers1

0

You need parenthesis:

the_date = df_hold.loc[(df_hold['Charge Code'] == '1250-001') & 
                       (df_hold['Billing Number'] == 500320), 'Date']

update:

the_date = df_hold.loc[(df_hold['Charge Code'] == '1250-001') & 
                       (df_hold['Billing Number'] == 500320), 'Date'].to_numpy()

or

the_date = df_hold.loc[(df_hold['Charge Code'] == '1250-001') & 
                       (df_hold['Billing Number'] == 500320), 'Date'].to_numpy()[0]
Scott Boston
  • 147,308
  • 15
  • 139
  • 187