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

Subsetting #45

Closed
versipellis opened this issue Dec 11, 2018 · 5 comments
Closed

Subsetting #45

versipellis opened this issue Dec 11, 2018 · 5 comments

Comments

@versipellis
Copy link

It's not immediately apparent to me how to subset in Pandas.jl compared to Python's pandas:

Where in Python pandas:

dftop30 = df[df['ORIGIN'].isin(top30)]

I roughly expect the Pandas.jl equivalent to be:

datatop30 = data[isin(data[:ORIGIN],top30),:]

This, however, results in:

PyError ($(Expr(:escape, :(ccall(#= /home/bversipellis/.julia/packages/PyCall/0jMpb/src/pyfncall.jl:44 =# @pysym(:PyObject_Call), PyPtr, (PyPtr, PyPtr, PyPtr), o, pyargsptr, kw))))) <class 'TypeError'>
TypeError("'Series' objects are mutable, thus they cannot be hashed",)
@malmaud
Copy link
Collaborator

malmaud commented Dec 11, 2018

Can you post complete code that reproduces the problem? Then I can take a look.

@versipellis
Copy link
Author

Sure.

using Pandas
df = DataFrame(Dict(:Group=>["Alpha", "Beta", "Alpha", "Charlie", "Beta", "Delta"], :name=>["James", "Jill", "Jake", "A name", "Yet another name", "Some person"]))
subset = ["Alpha","Delta"]

testsubset = df[isin(df[:Group],subset),:]

All I'm trying to do is subset a dataframe based on another object, which is trivial in Python pandas. The above code in Python for the last line:

testsubset = df[df['Group'].isin(subset)]

@malmaud
Copy link
Collaborator

malmaud commented Dec 12, 2018

You should index in Julia just like in Python:

df[isin(...)] without the extra , :] at the end. If you try doing that in Python, you get the same error message.

@malmaud malmaud closed this as completed Dec 12, 2018
@versipellis
Copy link
Author

Huh, weird, I had tried that before and run into an error. Looks like I'm doing it right now, sorry and thanks!

@malmaud
Copy link
Collaborator

malmaud commented Dec 12, 2018 via email

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

2 participants