admin管理员组文章数量:1026989
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']"
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']"
本文标签: Melting multiple columns in Python PandaStack Overflow
版权声明:本文标题:Melting multiple columns in Python Panda - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745669216a2162357.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论