Reputation: 31
I have Pandas DF like this:
Now I need to get UTB1050_1PCS if the condition match Brother and _1PCS and UTB1050_2PCS if my condition if Brother and _2PCS.
Many thanks in advance!!!
Upvotes: 1
Views: 80
Reputation: 132
Here is the data frame
import pandas as pd
list1=['_1PCS','_2PCS']
list2=['UTB1050_1PCS','UTB1050_2PCS']
list3=['Brother','Brother']
df=pd.DataFrame({'Variation':list1,
'Internal Code-Variation':list2,
'Brand':list3})
print(df)
Original Data
Variation Internal Code-Variation Brand
0 _1PCS UTB1050_1PCS Brother
1 _2PCS UTB1050_2PCS Brother
Filtered Data using Pandas .loc
import pandas as pd
list1=['_1PCS','_2PCS']
list2=['UTB1050_1PCS','UTB1050_2PCS']
list3=['Brother','Brother']
df=pd.DataFrame({'Variation':list1,
'Internal Code-Variation':list2,
'Brand':list3})
filtered = df.loc[(df['Brand']=='Brother') & (df['Variation']=='_2PCS')]
Output
Variation Internal Code-Variation Brand
1 _2PCS UTB1050_2PCS Brother
There are many ways to approach this problem, I also recommend looking into Indexing and Selecting
Upvotes: 1