[Solved] How can I create a vector in pandas dataframe from other attributes of the dataframe?


I think you need:

df['features'] = df.values.tolist()

print(df)
   Atr1 Atr2 features
0     1    A   [1, A]
1     2    B   [2, B]
2     4    C   [4, C]

If you have multiple columns and want to select particular columns then:

df = pd.DataFrame({"Atr1":[1,2,4],"Atr2":['A','B','C'],"Atr3":['x','y','z']})
print(df)
   Atr1 Atr2 Atr3
0     1    A    x
1     2    B    y
2     4    C    z

#Selecting Atr2 and Atr3 columns
df['features'] = df[['Atr2','Atr3']].values.tolist()
print(df)

   Atr1 Atr2 Atr3 features
0     1    A    x   [A, x]
1     2    B    y   [B, y]
2     4    C    z   [C, z]

1

solved How can I create a vector in pandas dataframe from other attributes of the dataframe?