I have a df constructed as such:
import pandas as pd
dic = {'001': [['one','two','three']],
'002': [['two', 'five', 'eight']],
'003': [['three','six','ten','twelve']]}
df = pd.DataFrame.from_dict(dic,orient='index')
df.reset_index(inplace=True)
df = df.rename(columns = {'index':'id',0:'values'})
print(df)
The resulting df looks like
id values
0 001 [one, two, three]
1 002 [two, five, eight]
2 003 [three, six, ten, twelve]
I would like to write a function that returns a dataframe or series of ids if a specific value in the corresponding list was called. For example:
def find_ids(value):
ids = psuedocode: if list contains value, then return id
return ids
So
find_ids('two')
should return
id
001
002
and
find_ids('twelve')
should return
id
003