In a pandas dataframe, I'd like to extract a character from a string column at the index given by another column. For example, given the following DataFrame
import pandas as pd
df = pd.DataFrame({"s": ["ACGT", "AAGA"], "i": [0, 2]})
# s i
# 0 ACGT 0
# 1 AAGA 2
I'd like to extract s[i]
for each row, to get
s i extracted
0 ACGT 0 A
1 AAGA 2 G
I would think I could do something like
df["s"].str.get(df["i"])
however .get()
only takes a single integer parameter, and not a series.
What's the best way to get this done?