[英]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.