# Replace entire columns in pandas dataframe

I would like to replace entire columns of a pandas dataframe with other columns, for example:

and I would like to replace the columns A and B. What I did is the following:

df['A']=dataFrame['opcodes'].values
df['B']=dataFrame['opt'].values


or also

df['A']=dataFrame['opcodes']
df['B']=dataFrame['opt']


but it does not work. In particular I get the following error:

KeyError: 'opcodes'


in both cases. Can anyone help me? Thank's in advance.

[EDIT] The original dataframe is the following:

on which I did the following modification:

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


now I would like to define an other dataframe on which only the 'opt' column and a column with the values 'opcodes' appear.

• See my edit below for clarification – HFulcher Nov 1 '19 at 14:56

You are getting a KeyError because 'opcodes' doesn't exist in dataFrame. Can you show us the contents of dataFrame not just df?
df = dataFrame[["opt", "opcodes"]].copy()