How can i extract one letter from one column from dataset?

Viewed 38

i'm trying to take the second letter from group columns. i used data['Group'][1:2] but it doesn't work

enter image description here

3 Answers

This will create a new column with that letter

df['Letter'] = df["Group"].apply(lambda x: x[1])

If you want a list and not a new column in the data frame:

letters = list(df["Group"].apply(lambda x: x[1]))

Maybe this works:

second_letter = []
for letter in df['Group']:
    i = letter[1:2]
    second_letter.append(i)
second_letter

Check Below code using STR SLICE:

df['Letter'] = df['Group'].str.slice(1,2)
Related