这似乎是非常基本的知识,但我被卡住了,尽管我有一些理论背景的数据处理(通过其他软件)。值得一提的是,我是蟒蛇和熊猫图书馆的新手。
所以。我有一个数据框架:

我的任务是将“系列名称”列的值作为单独的列(从长到宽)。我花了很长时间尝试不同的方法,但只有错误。
例如:
mydata = mydata.pivot(index=['Country', 'Year'], columns='Series Name', values='Value')我犯了个错误:
...很多短信..。ValueError:传递值的长度为2487175,索引意味着2
有人能引导我完成这个过程吗?谢谢。
它用于代码'mydata = mydata.pivot(index='Country‘、'Year’、columns='Series Name‘、Value=’Value‘)’错误消息:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-4-8169d6d374c7> in <module>
----> 1 mydata = mydata.pivot(index=['Country', 'Year'], columns='Series Name', values='Value')
~/anaconda3_501/lib/python3.6/site-packages/pandas/core/frame.py in pivot(self, index, columns, values)
5192 """
5193 from pandas.core.reshape.reshape import pivot
-> 5194 return pivot(self, index=index, columns=columns, values=values)
5195
5196 _shared_docs['pivot_table'] = """
~/anaconda3_501/lib/python3.6/site-packages/pandas/core/reshape/reshape.py in pivot(self, index, columns, values)
412 else:
413 indexed = self._constructor_sliced(self[values].values,
--> 414 index=index)
415 return indexed.unstack(columns)
416
~/anaconda3_501/lib/python3.6/site-packages/pandas/core/series.py in __init__(self, data, index, dtype, name, copy, fastpath)
260 'Length of passed values is {val}, '
261 'index implies {ind}'
--> 262 .format(val=len(data), ind=len(index)))
263 except TypeError:
264 pass
ValueError: Length of passed values is 2487175, index implies 2发布于 2019-12-31 00:25:02
快到了。结果表是

如何才能将“国家”和“年份”放在与其他专栏名称相同的水平,才能正常地输出到最佳状态?如果我出口像现在是‘国家’和‘年份’不包括在表中。
https://stackoverflow.com/questions/59532500
复制相似问题