简体   繁体   English

Python 3:获取与pandas dataframe某列中的值关联的索引名称

[英]Python 3: Get index names associated with the values in a certain column of pandas dataframe

I am trying to get a list of the corresponding index names of 500,000 values out of 2,000,000 entries in a pandas dataframe which are located in a specific column names "entity_id" (out of 1000+ columns).我正在尝试从 pandas dataframe 中的 2,000,000 个条目中获取 500,000 个值的相应索引名称列表,这些条目位于特定列名“entity_id”(超过 1000 个列中)。 My solution has been the following code:我的解决方案是以下代码:

    index_names_list= []
    for id in id_dataframe:
         index_names_list.append(full_data[full_data['entity_id'] == id ].index.values)

However, this runs very very slow.但是,这运行非常非常缓慢。 Can anyone suggest a better and more efficient way of doing it?任何人都可以提出更好,更有效的方法吗?

try this,尝试这个,

full_data.loc[full_data['entity_id'].isin(id_dataframe),:].index.tolist()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 获取pandas DataFrame中某一行的最大值的列名称 - Get column names for max values over a certain row in a pandas DataFrame 比较两个数据帧,只获取索引和列名不匹配的值 - compare two data frames and get only non matching values with index and column names pandas dataframe python 如何将值添加到 pandas dataframe 中的列中的某个索引(python) - how to add values to certain index in column in pandas dataframe (python) 熊猫数据框获取具有单元格中值的列名称 - Pandas dataframe get column names with values in cell 将索引的值与列名进行比较; Python Pandas - Compare the values of index with column names ; Python Pandas 将带有列名和索引名的 python pandas dataframe 转换为列表列表 - convert python pandas dataframe with column names and index names to list of lists Select Pandas 中的列名 dataframe 仅当行值满足 Python 中的特定条件时 - Select column names in Pandas dataframe only if row values meet a certain criteria in Python (重新)仅基于索引,pandas / python命名某些列名 - (re)naming only certain column names based on index, pandas/python Python Pandas 设置 Dataframe 数组中的索引和列名 - Python Pandas Setting Dataframe index and Column names from an array Python Pandas DataFrame:将列名称与行索引匹配” - Python Pandas DataFrame: Matching column names to row index'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM