【问题标题】:How to store the row value of a logic statement in python df如何在python df中存储逻辑语句的行值
【发布时间】:2021-07-26 19:23:08
【问题描述】:

我想要做的是将搜索功能添加到数据框中。我希望能够输入一个文件名并保存它发现的行。这样,当我使用 iloc 时,它会一起返回“文件名”和“修改数据”。

import pandas as pd
#....
df = pd.DataFrame(data, columns=['filename', 'modified_date'])
if df['filename'].str.contains('AAROW PDM Report') == TRUE:
    RowValue = #I want it to be equal to the row that was found true

print(df.iloc[[RowValue]])

【问题讨论】:

    标签: python pandas dataframe logic


    【解决方案1】:

    试试:

    RowValue = df['filename'].str.contains('AAROW PDM Report').idxmax()
    

    【讨论】:

    • RowValue = df['filename'].str.contains('AAROW PDM Report').idxmax() 关闭,但它给了我一个错误并建议 idx。但不管它现在是否有效。谢谢。
    • 我相信你想要行号。我修好了。
    猜你喜欢
    • 1970-01-01
    • 2018-08-10
    • 1970-01-01
    • 2021-07-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-14
    • 1970-01-01
    相关资源
    最近更新 更多