微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

与 Excel 相比,Python 中的数据透视表具有不同的格式

如何解决与 Excel 相比,Python 中的数据透视表具有不同的格式

假设我们有一个如下所示的数据框:

df

我想使用pandas数据透视表以这种方式对其进行格式化:

Pivot in Excel

然而,#include <cs50.h> #include <stdio.h> #include <string.h> string sub(string plaintext,string cipher); int main(int argc,string argv[]) { string cipher = argv[1]; // checks for whether an argument was provided if (argc != 2) { printf("Usage: ./substitution KEY\n"); return 1; } // checks for whether the cipher is 26 characters long else if (strlen(cipher) != 26) { printf("Key must contain 26 characters\n"); return 1; } // makes sure the cipher contains only non-alphabetical characters // also subtracts from 2015 (sum of all unique,upper-case letters) with each iteration to test for whether every character in the argument is unique int sum = 2015; for (int i = 0; i < strlen(cipher); i++) { if ((int) cipher[i] > 96 && (int) cipher < 123) { cipher[i] = (char) ((int) cipher[i] - 32); } if ((int) cipher[i] < 65 || ((int) cipher[i] > 90 && (int) cipher[i] < 97) || (int) cipher[i] > 122) { printf("Key must only contain alphabetical characters.\n"); return 1; break; } sum -= ((int) cipher[i]); } // DEBUG: prints 'sum' printf("%i\n",sum); // THIS IS THE PROBLEM STATEMENT // determines whether every character in the argument is unique if (sum != 0) { printf("Key must contain all unique characters.\n"); return 1; } // gets the plaintext from the user and prints out the cipher text using the 'sub' function string plaintext = get_string("plaintext: "); printf("ciphertext: %s\n",sub(plaintext,cipher)); } 给了我一个看起来像这样的输出

Pivot in Python

有人知道如何解决这个问题吗?

您可以使用以下代码来创建 df

df.pivot_table(index='Groupings',columns='columns',values=['value1','value2'])

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。