I have a dataframe like this:
df1
Name Category Age
Harry A 11
James B 23
Will A 19
I want to create a list of tuples using namedtuple
from collections
. The list should be like this:
output_list = [Variable(Name='Harry', Age=11), Variable(Name='James', Age=23), Variable(Name='Will', Age=19)]
This is what I've tried using 'itertuples'
output_list = list(df1[["Name","Age"]].itertuples(name='Variable', index=False))