[C++-sig] Boost Python. access pandas columns in the same order as in python

2016-10-05 Thread Vladimir Sakharuk
Hello All,


Trying to figure out how to c++ access pandas dataframe columns in the same 
order as they exist in the python.

in python:

import pandas


df = pandas.DataFrame.from_items([('CCC', [5]), ('BBB', [1]), ('AAA', [4])])


df.columns


# outputs Index([u'CCC', u'BBB', u'AAA'], dtype='object')

in C++ when passing df to foo.

foo(const boost::python::object in_obj)


{


  boost::python::stl_input_iterator it (in_obj), end;


  int index=0;


  for(; it != end; it++) {auto extracted = 
boost::python::extract (*it);   char const * colname = extracted; 
std::cout<<"index="

Re: [C++-sig] Boost Python. access pandas columns in the same order as in python

2016-10-05 Thread Stefan Seefeld
On 04.10.2016 09:05, Vladimir Sakharuk wrote:
>
> Hello All,
>
>
> Trying to figure out how to c++ access pandas dataframe columns in the
> same order as they exist in the python.
>
> in python:
>

[...]

> ||
> |//outputs regardless of original order of column names.   
> //index=0, colname=AAA//index=1, colname=BBB//index=2,
> colname=CCC|
>
> As you can see pythons' order 'CCC','BBB','AAA' is not same as c++
> 'AAA', 'BBB', 'CCC'. Looks like those order depend on object hasing.
>
>
> How could I get those values in the original order of pandas dataframe
> from C++?
>

I can't reproduce that; I see the same order (['CCC', 'BBB', 'AAA'])
both in Python and in C++ with your code above.

FWIW,
Stefan


-- 

  ...ich hab' noch einen Koffer in Berlin...

___
Cplusplus-sig mailing list
Cplusplus-sig@python.org
https://mail.python.org/mailman/listinfo/cplusplus-sig


Re: [C++-sig] Boost Python. access pandas columns in the same order as in python

2016-10-05 Thread Jim Bosch
Note that in Python 3.3+, dict order is nondeterministic, not just
arbitrary:

http://stackoverflow.com/questions/14956313/dictionary-ordering-non-deterministic-in-python3

So if these are invoking dict ordering under the hood, anything is possible.

Jim




On Wed, Oct 5, 2016 at 12:31 PM, Stefan Seefeld  wrote:

> On 04.10.2016 09:05, Vladimir Sakharuk wrote:
> >
> > Hello All,
> >
> >
> > Trying to figure out how to c++ access pandas dataframe columns in the
> > same order as they exist in the python.
> >
> > in python:
> >
>
> [...]
>
> > ||
> > |//outputs regardless of original order of column names.
> > //index=0, colname=AAA//index=1, colname=BBB//index=2,
> > colname=CCC|
> >
> > As you can see pythons' order 'CCC','BBB','AAA' is not same as c++
> > 'AAA', 'BBB', 'CCC'. Looks like those order depend on object hasing.
> >
> >
> > How could I get those values in the original order of pandas dataframe
> > from C++?
> >
>
> I can't reproduce that; I see the same order (['CCC', 'BBB', 'AAA'])
> both in Python and in C++ with your code above.
>
> FWIW,
> Stefan
>
>
> --
>
>   ...ich hab' noch einen Koffer in Berlin...
>
> ___
> Cplusplus-sig mailing list
> Cplusplus-sig@python.org
> https://mail.python.org/mailman/listinfo/cplusplus-sig
>
___
Cplusplus-sig mailing list
Cplusplus-sig@python.org
https://mail.python.org/mailman/listinfo/cplusplus-sig

Re: [C++-sig] Boost Python. access pandas columns in the same order as in python

2016-10-05 Thread Vladimir Sakharuk
It looks like I had other "bug" aka replacing with OrderedDict solved the 
problem.


From: Cplusplus-sig 
 on behalf of 
Jim Bosch 
Sent: Wednesday, October 5, 2016 12:36 PM
To: Development of Python/C++ integration
Subject: Re: [C++-sig] Boost Python. access pandas columns in the same order as 
in python

Note that in Python 3.3+, dict order is nondeterministic, not just arbitrary:

http://stackoverflow.com/questions/14956313/dictionary-ordering-non-deterministic-in-python3

So if these are invoking dict ordering under the hood, anything is possible.

Jim




On Wed, Oct 5, 2016 at 12:31 PM, Stefan Seefeld 
mailto:ste...@seefeld.name>> wrote:
On 04.10.2016 09:05, Vladimir Sakharuk wrote:
>
> Hello All,
>
>
> Trying to figure out how to c++ access pandas dataframe columns in the
> same order as they exist in the python.
>
> in python:
>

[...]

> ||
> |//outputs regardless of original order of column names.
> //index=0, colname=AAA//index=1, colname=BBB//index=2,
> colname=CCC|
>
> As you can see pythons' order 'CCC','BBB','AAA' is not same as c++
> 'AAA', 'BBB', 'CCC'. Looks like those order depend on object hasing.
>
>
> How could I get those values in the original order of pandas dataframe
> from C++?
>

I can't reproduce that; I see the same order (['CCC', 'BBB', 'AAA'])
both in Python and in C++ with your code above.

FWIW,
Stefan


--

  ...ich hab' noch einen Koffer in Berlin...

___
Cplusplus-sig mailing list
Cplusplus-sig@python.org
https://mail.python.org/mailman/listinfo/cplusplus-sig

___
Cplusplus-sig mailing list
Cplusplus-sig@python.org
https://mail.python.org/mailman/listinfo/cplusplus-sig