假设我们有一个panda数据帧,它有三个特性,如下所示。在
每一行代表一个客户,每一列代表这个客户的一些特性。在
我想得到行号并将它们添加到列表中,或者根据它们的特征值不将它们添加到列表中。在
假设,如果featureUrea小于100或FEATUREB大于500,我们希望找到行号。在
我已经为此编写了一些代码,如下所示。在import pandas as pd
d = [{‘feature1’: 100, ‘feature2’: 520, ‘feature3’: 54},
{‘feature1’: 102, ‘feature2’: 504, ‘feature3’: 51},
{‘feature1’: 241, ‘feature2’: 124, ‘feature3’: 4},
{‘feature1’: 340, ‘feature2’: 830, ‘feature3’: 700},
{‘feature1’: 98, ‘feature2’: 430, ‘feature3’: 123}]
df = DataFrame(d)
print(df)
print(“—-“)
dataframe1 = df[(df[‘feature1’] < 100)]
dataframe2 = df[(df[‘feature2’] > 500)]
print(dataframe1)
print(dataframe2)
here I would like to get row number temp and add them to result list
程序输出
^{pr2}$
我不知道如何组合dataframe1和dataframe2,然后得到它们的行号。如果你知道怎么做的话,你能和我分享一下吗?在
我想看看这样的结果列表result = [ 4, 0, 1, 3]
Original: https://blog.csdn.net/weixin_28912709/article/details/113638976
Author: 懒得思考的聪明人
Title: python pandas获取行号_pandas dataframe获取行号并添加到lis
原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/743238/
转载文章受原作者版权保护。转载请注明原作者出处!