i'm trying to take the second letter from group columns. i used data['Group'][1:2] but it doesn't work
CodePudding user response:
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]))
CodePudding user response:
Maybe this works:
second_letter = []
for letter in df['Group']:
i = letter[1:2]
second_letter.append(i)
second_letter
CodePudding user response:
Check Below code using STR SLICE:
df['Letter'] = df['Group'].str.slice(1,2)