Not sure how to word this, but I'm trying to reference an f string within another f string.
I have lists, which could be variable in length.
list_a = ['a', 'b', 'c']
list_b = ['a', 'b', 'c', 'd']
these are dataframe column names, which I'm trying to reference and pull the value of a specific row like so:
desc = " \n".join(
[
f"- {df.iloc[i]['a']} | {df.iloc[i]['b']} | plus some additional text here"
for i in df[0:3].index
]
)
but I need the description to be variable, depending on if I am looping through list_a or list_b.
I've tried something like this:
attempt = ' | '.join(f"{{df[i][{j}]}}" for j in list_a)
desc = " \n".join(
[
f"- {attempt} | plus some additional text here"
for i in df[0:3].index
]
)
but instead of looking up the value of the dataframe, it prints the string:
- {df.iloc[i]['a']} | {df.iloc[i]['b']} ... plus some additional text here
- {df.iloc[i]['a']} | {df.iloc[i]['b']} ... plus some additional text here
what am I missing here?