Melting multiple columns in Python Panda - Stack Overflow

Melting multiple columns in Python PandaHello all,I stack in this coding for two day. I want to get a

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']"

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745669218a4639303.html

相关推荐

  • Melting multiple columns in Python Panda - Stack Overflow

    Melting multiple columns in Python PandaHello all,I stack in this coding for two day. I want to get a

    21天前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信