gpt4 book ai didi

python - 按列中的值获取行的索引

转载 作者:太空宇宙 更新时间:2023-11-03 13:39:06 25 4
gpt4 key购买 nike

我有以下数据框:

     date         value
0 2016-01-01 gfhgh
1 2016-01-02 acgb
2 2016-01-03 yjhgs

我需要获取日期为预定义值的行的索引。例如,对于 2016-01-02,我需要获取 1。每个日期都是唯一的。

最佳答案

假设日期字段是字符串:

df[df.date == '<the date value whose index you want>'].index.tolist()

将返回一个索引列表,其日期等于您提供的日期值

关于python - 按列中的值获取行的索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34738732/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com