在 DataFrame.pivot() 上,结果与我的预期不同
我指的是 https://github.com/pandas-dev/pandas/tree/main/doc/cheatsheet。
如您所见,如果我使用 pivot()
,则所有值都位于第 0 行和第 1 行中。
如果我使用pivot()
,结果有所不同,如下所示。
pivot()
之前的 DataFrame:
pivot()
之后的数据帧:
这个结果是故意的吗?
I'm referring to
https://github.com/pandas-dev/pandas/tree/main/doc/cheatsheet.
As you can see, if I use pivot()
, then all values are in row number 0 and 1.
But if I do use pivot()
, the result was different like below.
DataFrame before pivot()
:
DataFrame after pivot()
:
Is the result on purpose?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在您的数据中,灰色列(行的索引)丢失:
添加灰色列:
现在您可以旋转:
花时间阅读 如何旋转数据框?
In your data, the grey column (index of the row) is missing:
Add the grey column:
Now you can pivot:
Take the time to read How can I pivot a dataframe?