根据熊猫数据框中的两个列值查找列值

时间:2020-04-06 16:30:38

标签: pandas dataframe loc

我需要基于两个特定的列值从一列中获取值。

示例数据框:

   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

我想获取具有收费代码1250-001和帐单号500320(应为3/8/20)的行的日期

我正在尝试使用以下行:

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

并收到以下错误:

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

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

我得到以下信息:

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

有没有办法自己获取日期?

1 个答案:

答案 0 :(得分:0)

您需要括号:

@Html.Action("RenderPartial", "ControllerWithNoModelMethod")
@Html.Action("RenderPartial", "ControllerWithModelMethod", new { content = Model })
@Html.RenderAction("RenderPartial", "ControllerWithNoModelMethod")
@Html.RenderAction("RenderPartial", "ControllerWithModelMethod", new { content = Model })

更新:

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

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