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

How to convert a Pandas DataFrame to Julia one without copy? #135

Closed
ShuhuaGao opened this issue Mar 25, 2022 · 2 comments
Closed

How to convert a Pandas DataFrame to Julia one without copy? #135

ShuhuaGao opened this issue Mar 25, 2022 · 2 comments

Comments

@ShuhuaGao
Copy link
Contributor

In Python 3.9:

import pandas as pd
import numpy as np

from juliacall import Main as jl

pd_df = pd.DataFrame({'Name': ['Tom', 'nick', 'krish', 'jack'],
                      'Age': [20, 21, 19, 18]})
jl.seval("using DataFrames")
jl_df = jl.DataFrame(pd_df)
jl_df[1, 2] = -100
pd_df.iloc[0, 1]  # still 20

Since PythonCall.PyPandasDataFrame is compatible with Table.jl and Julia DataFrame's constructor does not copy a table by default, how to explain the above behaviour? Is there any way to avoid data copying?

@cjdoris
Copy link
Collaborator

cjdoris commented Mar 25, 2022

Indeed accessing columns of a PyPandasDataFrame is currently a copying operation. That whole functionality isn't very well developed so far - but contributions are welcome.

@cjdoris
Copy link
Collaborator

cjdoris commented May 27, 2022

The latest release now uses no-copy views of columns where possible, so your above example mutates pd_df as desired.

@cjdoris cjdoris closed this as completed May 27, 2022
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