Suppose I have a list that is made up of 3 dataframes, namely
lst = [df1,df2,df3]
where:
d1 = {'col1':['a','b','c','d','e']}
df1= pd.DataFrame(d1)
d2 = {'col1':['b','c','a','d','e']}
df2= pd.DataFrame(d2)
d3 = {'col1':['b','c','e','d','a']}
df3= pd.DataFrame(d3)
for each df in the lst I want to go through col1 and find the rank of letter a and make a new dataframe from it, the output should look like:
dataframe index rank of a
0 0 0
1 1 2
2 2 4
namely, for df1 letter a is on 0th index, for df2 letter a is on 2nd index and so on. I wonder how one does this?
I tried doing:
ll = []
for i in lst:
x = i[i['col1'].isin(['a'])]
ll.append(x)
which extracts the ranks of a, I then tried
lll = []
for i in ll:
x = ll[i][0]
lll.append(x)
which doesn't work and I think my approach generally is not the best way.