Melting multiple columns in Python Panda
Hello all,
I stack in this coding for two day. I want to get a proper df for EDA and then machine learning. I am new to Python. Could you help?
My data
enter image description here
After pivot
enter image description here
tourism5 = tourism4.pivot_table(index=["Year"], columns=["Tourists to Ireland", "Area of Residence"], values="VALUE")
tourism5
tourism6 = tourism5.melt(id_vars=["Year"], var_name= ["Average Stay Nights", "Tourists Expenditure", "Tourists Number"],value_name="VALUE")
tourism6
I try to melt it. But, it keeps giving error message. Thanks for your help in advance.
File C:\Users\anaconda3\Lib\site-packages\pandas\core\reshape\melt.py:74, in melt(frame, id_vars, value_vars, var_name, value_name, col_level, ignore_index)70 if missing.any():71 missing_labels = [72 lab for lab, not_found in zip(labels, missing) if not_found73 ]---> 74 raise KeyError(75 "The following id_vars or value_vars are not present in "76 f"the DataFrame: {missing_labels}"77 )78 if value_vars_was_not_none:79 frame = frame.iloc[:, algos.unique(idx)]
KeyError: "The following id_vars or value_vars are not present in the DataFrame: ['Year']"