r/PySpark

242 archived posts · Oct 2014 – Sep 2026

Random post


u/femibyte•

​

I have a Pyspark project that requires a custom ML Pipeline Transformer written in Scala. What is the best practice regarding project organization ? Should I include the scala files in the general Python project or should they be in a separate repo ? Opinions and suggestions welcome.

Suppose my Python projects looks like this:

project    
  - etl   
  - model   
  - scripts   
  - tests

The model directory would contain Spark ML code for the model as well as the ML Pipeline code So where should the Scala code for the custom transformer live? The structure for this looks like this:

custom_transformer/src/main/scala    
  - com/mycompany/dept/proje
62


u/DrData82•

In the process of converting some SAS code to PySpark and we previously used a macro variable for the where statement in this code. In adapting to PySpark, I'm trying to pass a list of dates to the where statement, but I keep getting errors. I want the SQL code to pull all data from those 3 months. Any pointers?

month_list = ['202107', '202108', '202109']
sql_query = """ (SELECT * 
                 FROM Table_Blah
                 WHERE (to_char(DateVariable,'yyyymm') IN '{}')
                 ) as table1""".format(month_list)
56

u/Modest_Gaslight•

So I have a project to complete using PySpark and I'm at a total loss. I need to retrieve data from 2 APIs (which I've done, see below code). I now need to pre-process and store the data, visualise the number of cases and deaths per day and then perform a k means clustering analysis on one of the data sets identifying which weeks cluster together. This is pretty urgent work given the nature of COVID and I just don't understand how to use PySpark at all and would really appreciate any help you can give me, thanks.

Code for API data request:

# Import all UK data from UK Gov API
from requests import get


def get_data(url):
    response = get(endpoint, timeout=
55

u/rawlingsjj•

So I have a spark dataframe where I need to get the count/length of the dataframe but the count method is very very slow. I can’t afford to use the .count() because I’ll be getting the count for about 16 million options.

Is there any alternative to this? Thank you

56

Hello, I have created a SON algorithm implementation with Apriori step in pyspark to find frequent itemsets. The algorithm works fine with different toy datasets that I have tested that contain up to 4 million records. However, when I use the algorithm on the IMDB dataset, which I have imported from Kaggle and modified in such a way to obtain movies as baskets and actors as items, the algorithm does not work.

Here is the link to my github page with the code:https://github.com/giusi07/AMD-PROJECT

In cell 58 there is the stack error trace. I have tried everything but I cannot solve the problem.

I hope someone can help me!!

53

u/AnonymouseRedd•

Hello,

I have a PySpark problem and maybe someone faced the same issue. I'm trying to read a xlsx file to a Pyspark dataframe using com.crealytics:spark-excel. The issue is that the xlsx file has values only in the A cells for the first 5 rows and the actual header is in the 10th row and has 16 columns (A cell to P cell).

When I am reading the file the df does not have all the columns.

Is there a specific way/ a certain jar file + pyspark version so that I can read all the data from the xlsx file and have the defacul header _c0 _c1 .... _c16 ?

Thank you !

44

u/data_analist•

Pyspark code looks gross, especially when chaining multiple operations with dataframes. Anyone have some documented style guide for pyspark code specifically?

35

u/dthure•

I am working with Pyspark in Azure Databricks. I have a stream set up that parses log files in json format. All data points have the same schema structure however some of the properties are named differently for different data points. The property names differ by the case type of the first letter only.

Example: The schema contains a property named "isAdmin". However for some of the data points this same property is named "IsAdmin". Since in the schema definition the property is named "isAdmin" all data points containing a property called "IsAdmin" will be stored as "isAdmin == null". I would like to store the value contained in either "isAdmin" or "IsAdmin" depending on which of them are

31

u/ModSupportBot•

r/PySpark is ready for a fresh start, new energy, new direction, and someone like you to bring it back to life. If you’ve been thinking about growing your impact without starting from scratch, this is your chance!

Ready to take it over?

Head to r/RedditRequest to submit your request and make it yours before it’s taken.

First things first

To request this subreddit, make sure you:

30