0
$\begingroup$

I have a dataframe which is the following:

enter image description here

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.

Can somebody please help me? Thank's in advance.

$\endgroup$

2 Answers 2

1
$\begingroup$

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())
$\endgroup$
1
$\begingroup$

use lambda function like as follows

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.