Hi all,
I’m trying to copy data from a dataframe df
to a second dataframe dff
based off the names of the columns which are held in a list. This is for a dashboard which will use a checklist to display selected data on a line graph, and is based off the tutorial by Adam of charming data. The relevant code here would go in the update_graph()
function in his example.
To copy specific columns of a dataframe I’d usually write:
df = pd.read_csv('supercoolcsvfile.csv')
options_chosen=['Column A',
'Column B',
]
dff=df[['Column A', 'Column B']]
I tried this, but it doesn’t work:
df = pd.read_csv('supercoolcsvfile.csv')
options_chosen=['Column A',
'Column B',
]
dff=df[[options_chosen]]
Returning the error:
KeyError: "None of [Index([('Column A, 'Column B)')], dtype='object')] are in the [columns]"