Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pandas .loc() function chokes while using PyCall #705

Closed
milanhej opened this issue Aug 7, 2019 · 2 comments
Closed

Pandas .loc() function chokes while using PyCall #705

milanhej opened this issue Aug 7, 2019 · 2 comments

Comments

@milanhej
Copy link

milanhej commented Aug 7, 2019

PyCall has proven invaluable to me -- thanks! -- but I have been unable to use the important .loc() function (handy in locating specific rows and columns of a dataframe) under Pandas.

The following python works to locate two rows and a column:

import pandas as pd
data = {'Name':['Bob', 'Ruth', 'Tina', 'Jack'], 'Age':[30, 25, 18, 31]} 
df = pd.DataFrame(data)
df.loc[0:1,"Age"]

But under Julia while using PyCall, the equivalent code fails:

using PyCall
pd = pyimport("pandas")
data = Dict("Name"=> ["Bob", "Ruth", "Tina", "Jack"], "Age" => [30, 25, 18, 31] )
df = pd.DataFrame(data)
df.loc(1:2,"Age")

Thanks for any insight how to work around this issue.

@tkf
Copy link
Member

tkf commented Aug 9, 2019

I think we need to define getindex(::PyObject, ...) so that it just works. Until then, you need to use https://github.com/JuliaPy/Pandas.jl or just do py""" .... """.

@stevengj
Copy link
Member

stevengj commented Aug 28, 2019

The equivalent code right now is:

get(df.loc, (0:1,"Age"))

(The get(o, key) function is the documented translation of Python's o[key] at the moment: https://github.com/JuliaPy/PyCall.jl#pyobject).

We will implement getindex eventually, but have been holding off because getindex used to be used for getting attributes in PyCall, before dot overloading. That's why it's currently deprecated. Once enough PyCall-using packages have upgraded, we can switch to making getindex in Julia be equivalent to the Python o[key].

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants