将列值分为单独的行(Pivot)

发布于 2025-02-08 07:49:19 字数 413 浏览 0 评论 0原文

我有一个看起来像这样的数据集:

App    Downloads    Permissions
A      123          56
B      89           12

我想修改df看起来像这样:

App    Title              Value    
A      Downloads          123
A      Permissions        56
B      Downloads          89
B      Permissions        12

我该如何实现?我已经研究了Pivot_table功能,但似乎与我试图实现的目标有些不同。另外,不确定我要创建的新列的名称(标题/值)

I have a dataset that looks like this:

App    Downloads    Permissions
A      123          56
B      89           12

I want to modify the dfto look like like this:

App    Title              Value    
A      Downloads          123
A      Permissions        56
B      Downloads          89
B      Permissions        12

How can I achieve this? I have looked into the pivot_table functions but it seems a bit different than what I am trying to achieve. Also, not sure how to add the names (Title/Value) for the new columns I want to create

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

独守阴晴ぅ圆缺 2025-02-15 07:49:19

您可以使用融化获得这些结果

df.melt(value_vars = ['Downloads', 'Permissions'])

You could use melt to get these results

df.melt(value_vars = ['Downloads', 'Permissions'])
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文