Lets assume we have a panda dataframes with three features as represented below.
Each rows is representing a customer and each column representing some features of this customer.
I would like to get row number and add them to a list or not add them to list according to their feature values.
Lets say, we would like to find row numbers if FEATUREA less than 100 or FEATUREB more than 500.
I have written some code for this as you can see below.
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
Output of the program
feature1 feature2 feature3
0 100 520 54
1 102 504 51
2 241 124 4
3 340 830 700
4 98 430 123
----
feature1 feature2 feature3
4 98 430 123
feature1 feature2 feature3
0 100 520 54
1 102 504 51
3 340 830 700
I could not figure out how to combine dataframe1 and dataframe2 and then get theirs row number. Could you please share if you know how to do it?
I would like to see a result list like that
result = [ 4, 0, 1, 3]