# use .apply() function to change values to a column of the dataframe

I have a dataframe which is the following:

and I would like to consider only the column of instructions and keep just the values push, test, mov, test ,....., so just the first word of each string inside each list. What I am doing is the following:

dataFrame['opcodes'] = dataFrame['instructions'].apply(instruction.split()[0] for instruction in dataFrame['instructions'])


but I get the following message:

TypeError: 'generator' object is not callable


so, my objective is to change the values only of the column instructions.

Given you dataframe is data, use the below apply() function:

For column with list of words separated by space:

data['New_instructions'] = data['instructions'].apply(lambda x: [i.split()[0].strip()for i in x])


For column with single list word:

data['New_instructions'] = data['instructions'].apply(lambda x: x.split()[0].strip())


use lambda function like as follows

dataFrame['opcodes'] = dataFrame['instructions'].apply(lambda x:[i.split()[0] for i in x])