我有以下数据帧(df):
科鲁阿
|
上校B
|
上校
|
123
|
A.
|
1Q
|
124
|
B
|
L1
|
125
|
B
|
QW
|
126
|
A.
|
E2
|
如果用户选择了特定的列和值,则整行应保存为新的数据帧。例如,如果用户选择Col_A 123,则输出应如下所示:
如果用户选择Col_B:B和Col_A:125,则输出应符合以下要求:
如果用户选择Col_B:B,则输出应如下所示:
科鲁阿
|
上校B
|
上校
|
124
|
B
|
L1
|
125
|
B
|
QW
|
我该怎么做?
到目前为止我试过什么?
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])
如果指定了Col_a和Col_B,则上述脚本不会提取特定数据。如果我指定Col_A=124和Col_B=B,那么所有结果都是Col_B。
期望输出: