2020-11-27

one variable many values python

I made dataframe from a dict containing some variables which have more than one value. I'm trying to get all the possible matches in the other column when I search these variables. So when I try to access 1 and 2 for a, it only processes the first match! I'm stuck using re.findall.

Items = {'lett': ['a','a','b', 'b'],
         'numb': ['1', '2', '3', '4']}
df = pd.DataFrame(Items, columns = ['lett', 'numb'])
M = df.to_numpy()
    
def start():
    enw = input("Input Any item: ")
    if enw in M[:,0]:
        print ('the price is:', df.loc[df.lett == enw, 'numb'].values[0])
        print('input another item')
        start()
start()


from Recent Questions - Stack Overflow https://ift.tt/367fMT5
https://ift.tt/eA8V8J

No comments:

Post a Comment