与 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 (将#修改为@)