最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Melting multiple columns in Python Panda - Stack Overflow

programmeradmin1浏览0评论

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']"
发布评论

评论列表(0)

  1. 暂无评论