如何将Pandas列中的每个单元格变成自己的列?

时间:2019-11-14 19:34:38

标签: python pandas dataframe nltk

我在Python中有一个Pandas数据框:

        Http http = new http();
        Profile p = [SELECT Id FROM Profile WHERE Profile.Name = 'S3 Test User' LIMIT 1];
        S3_Settings__c s3 = S3_Settings__c.getInstance(p.Id);
        String exp = String.valueOf(Cache.Session.get('expiration'));
        String sessionToken = String.valueOf(Cache.Session.get('token'));

        if(exp == null || exp == '' || (DateTime) JSON.deserialize('"' + exp + '"', DateTime.class) < System.now()) {
            requestSessionToken();
        }

        sessionToken = String.valueOf(Cache.Session.get('token'));
        DateTime expires = (DateTime) JSON.deserialize('"' + String.valueOf(Cache.Session.get('expiration')) + '"', DateTime.class);
        String accessKeyId =  String.valueOf(Cache.Session.get('accessKeyId'));
        String accessSecret = String.valueOf(Cache.Session.get('secret'));

        String bucketname = s3.Recording_Bucket__c;
        String host = 's3.amazonaws.com';  
        String formattedDateString = Datetime.now().formatGMT('EEE, dd MMM yyyy HH:mm:ss z');
        String method = 'GET';
        String filePath = 'https://' + bucketname + '.' + host + '/' + filename; 
        HttpRequest req = new HttpRequest();
        req.setMethod(method);
        req.setEndpoint(filePath);
        req.setHeader('Host', bucketname + '.' + host);
        req.setHeader('Connection', 'keep-alive');
        String stringToSign = 'GET\n\n' + 'x-amz-security-token=' + sessionToken + '&expiration=' + expires + '\n' + formattedDateString + '\n/' + '/' + bucketname + '/' + filename;
        System.debug('SIGN ' + stringToSign);
        String encodedStringToSign = EncodingUtil.urlEncode(stringToSign, 'UTF-8');
        Blob mac = Crypto.generateMac('HMACSHA1', blob.valueof(stringToSign),blob.valueof(accessSecret));
        String signedKey  = EncodingUtil.base64Encode(mac);

        String authHeader = 'AWS' + ' ' + accessKeyId + ':' + signedKey;
        req.setHeader('Date', formattedDateString);
        //req.setHeader('x-amz-security-token', sessionToken); //AWS returns 'invalid signature' if this is set

        req.setHeader('Authorization',authHeader);

        HttpResponse resp = http.send(req);

我希望“关键字”中的每个项目都是其自己的列,以下单元格中的“频率”中包含数据:

   Date           Count Frequency        Keyword
0  2019-11-05     18   0.000269       republican
1  2019-11-05      1   0.000015         democrat
2  2019-11-05     58   0.000865         congress
3  2019-11-05      0   0.000000       democratic
4  2019-11-05      0   0.000000            lesko
5  2019-11-05      0   0.000000            congo
6  2019-11-05      0   0.000000           carbon
7  2019-11-05      2   0.000030   climate_change

我正在像这样制作我的第一个数据框:

Date            republican democrat congress democratic lesko    congo    carbon   climate_change
2019-11-05      0.000269   0.000015 0.000865 0.000000   0.000000 0.000000 0.000000 0.000030

'Date','Count'和'Frequency'都是在其他地方计算的,出于简单起见,我将为此保留代码(除非有人要求将它们包括在内)。

感谢您的帮助。

0 个答案:

没有答案