cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results for 
Search instead for 
Did you mean: 

What is the proper way to import the new pyspark.pandas library?

cconnell
Contributor II

I am moving an existing, working pandas program into Databricks. I want to use the new pyspark.pandas library, and change my code as little as possible. It appears that I should do the following:

1) Add from pyspark import pandas as ps at the top

2) Change all occurrences of pd.pandas_function to ps.pandas_function

Is this correct?

1 ACCEPTED SOLUTION

Accepted Solutions

Dan_Z
Databricks Employee
Databricks Employee

Yes- that is a great start. Right now code coverage is at 83%, and we are shooting for 90%. Please file an issue if you find a gap you need filled. Please note- pandas on Spark (koalas) does some interesting things with the way it distributes the indexes of large dataframes. It may good to review starting at 20:20 here: https://databricks.com/session_na20/koalas-making-an-easy-transition-from-pandas-to-apache-spark

View solution in original post

11 REPLIES 11

Dan_Z
Databricks Employee
Databricks Employee

Yes- that is a great start. Right now code coverage is at 83%, and we are shooting for 90%. Please file an issue if you find a gap you need filled. Please note- pandas on Spark (koalas) does some interesting things with the way it distributes the indexes of large dataframes. It may good to review starting at 20:20 here: https://databricks.com/session_na20/koalas-making-an-easy-transition-from-pandas-to-apache-spark

Thank you. I am porting this code and will file issues as I see them… https://medium.com/@chuck.connell.3/vaccines-vs-mortality-correlation-at-the-county-level-922a10236a...

Hubert-Dudek
Esteemed Contributor III

import pyspark.pandas as ps but as code coverage is 83% as @Dan Zafar​ said it can not guarantee that your old code will work. You can find more here on that blogpost https://databricks.com/blog/2021/10/04/pandas-api-on-upcoming-apache-spark-3-2.html

I have read that blog. It was helpful but implied that I can move code from laptop pandas to spark pandas by changing one line of code, which does not seem true.

Dan_Z
Databricks Employee
Databricks Employee

That''s right, expect some minor refactoring.

Anonymous
Not applicable

Make sure to use the 10.0 Runtime which includes Spark 3.2

Yes, did that. I am now porting the code, finding workarounds to problems, and keeping a list of issues. Will write it all up as an article on Medium.

Anonymous
Not applicable

Cool, make sure to link it here when you're finished.

Yes. Do you want me to create official issues at apache/spark, or let someone on your team do it from my notes?

Anonymous
Not applicable

Official issues is the best way to go. That way you can reference them in the future and show your work off!

I created some issues, such as this one. Please let me know if I did anything wrong, so I can fix them. Thanks!

https://issues.apache.org/jira/browse/SPARK-37180

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you won’t want to miss the chance to attend and share knowledge.

If there isn’t a group near you, start one and help create a community that brings people together.

Request a New Group