I have the following dataframe (df):
| Col_A | Col_B | Col_C |
|---|---|---|
| 123 | A | 1Q |
| 124 | B | L1 |
| 125 | B | QW |
| 126 | A | E2 |
If the user selects a particular column and the value the entire row should be saved as a new dataframe. For example, if the user selects Col_A 123 the output should be the following:
| Col_A | Col_B | Col_C |
|---|---|---|
| 123 | A | 1Q |
If the user selects Col_B: B and Col_A: 125 then the output should e the following:
| Col_A | Col_B | Col_C |
|---|---|---|
| 125 | B | QW |
If the user selects Col_B: B then the output shoud be the following:
| Col_A | Col_B | Col_C |
|---|---|---|
| 124 | B | L1 |
| 125 | B | QW |
How do I do that?
What I tried so far?
import pandas as pd
import numpy as np
df= pd.read_csv('Table.csv')
print('Enter the value as 99 if the Col_A or Col_B is not known')
Col_A_value= (input(str("Enter tag of your interest separated by ',': ")).split(","))
Col_B_value= (input(str("Enter iris_image_id of your interest separated by ',': ")).split(","))
input_table = []
for i,j in itertools.product(Col_A_value, Col_B_value):
if len(i) > 0 and len(j)==0:
input_table.append(df[df['Col_A'] == i])
elif i != '99' and len(j)> 0:
input_table.append(df[df['Col_A'] == i])
The above script does not extract a particular data if Col_A and Col_B are specified. If I specify Col_A = 124 and Col_B = B it results everything in col_B.
Desired output:
| Col_A | Col_B | Col_C |
|---|---|---|
| 124 | B | L1 |
