Chris has the Right answer.  If you want a more brute force attack, you could 
also fall back on Perl:

>>     my $age_col=$self->data->slice(",0:0"); 
>>     $age_col = pdl(float, $age_col->list);

(Mobile)

> On Aug 21, 2017, at 1:05 PM, Chris Marshall <[email protected]> wrote:
> 
> Hi Adam-
> 
> PDL::Char data is for arrays of fixed length strings
> and I'm not sure how the data conversions and indexing
> are handled.  If you have columns of data I suggest
> taking a look at rcols() which allows you to specify
> column separators and whether the data is read into
> a PDL or into a perl array.  The examples at the bottom 
> of the rcols documentation (pdldoc rcols from the shell
> prompts or help rcols from the pdl2 or perldl shells)
> should help with what is possible.
> 
> --Chris
> 
>> On Mon, Aug 21, 2017 at 2:42 PM, Adam Russell <[email protected]> wrote:
>> Suppose I want to convert the first col of a PDL::Char to a float. When I do 
>> this
>> 
>>     my $age_col=$self->data->slice(",0:0");
>> 
>> I get the first column just fine, it looks like this 
>> 
>> [
>>  [ '39'  ] 
>>  [ '50'  ] 
>>  [ '38'  ] 
>>  [ '53'  ] 
>>  [ '28'  ] 
>>  [ '37'  ] 
>>  [ '49'  ] 
>>  [ '52'  ] 
>>  [ '31'  ] 
>>  [ '42'  ] 
>>  [ '37'  ] 
>>  [ '30'  ] 
>>  [ '23'  ] 
>>  [ '32'  ] 
>>  [ '40'  ] 
>>  [ '34'  ] 
>> ] 
>> 
>> but if I try and convert it to a float I get a bunch of gibberish?
>>     my $age_col=$self->data->slice(",0:0"); 
>>     $age_col = float $age_col;
>> 
>> [
>>  [ 'LBdB'  ] 
>>  [ 'TB@B'  ] 
>>  [ 'LB`B'  ] 
>>  [ 'TBLB'  ] 
>>  [ 'HB`B'  ] 
>>  [ 'LB\B'  ] 
>>  [ 'PBdB'  ] 
>>  [ 'TBHB'  ] 
>>  [ 'LBDB'  ] 
>>  [ 'PBHB'  ] 
>>  [ 'LB\B'  ] 
>>  [ 'LB@B'  ] 
>>  [ 'HBLB'  ] 
>>  [ 'LBHB'  ] 
>>  [ 'PB@B'  ] 
>>  [ 'LBPB'  ] 
>> ] 
>> 
>> 
>> What am I doing wrong?
>> I am using PDL:Char because much of the rest of the columns are indeed 
>> Strings and so I thought it wuld make sense to just use PDL::Char to store 
>> everything and then selectively convert a column or two to float as needed.
>> 
>> 
>> 
>> 
>> ------------------------------------------------------------------------------
>> Check out the vibrant tech community on one of the world's most
>> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
>> _______________________________________________
>> pdl-general mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/pdl-general
>> 
> 
> ------------------------------------------------------------------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> pdl-general mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/pdl-general
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
pdl-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pdl-general

Reply via email to