[Python] Can not read a json file by Pyspark which is located publicly on the cloud [closed]

Discussão em 'Python' iniciado por Stack, Fevereiro 24, 2025.

  1. Stack

    Stack Membro Participativo

    The following code gets error in Pyspark, however can read by Pandas:

    from pyspark.sql import SparkSession

    spark= SparkSession.builder.master("local[1]").appName("SparkByExamples.com").getOrCreate()

    file_path = "gs://data-analytics-demos/churn/chat_transcripts.json"

    # Read the JSON file into a Spark DataFrame
    df_sentiment = spark.read.json(file_path)


    Below is the error message: raise Py4JJavaError( "An error occurred while calling {0}{1}{2}.\n". --> format(target_id, ".", name), value)

    However, the following works in Pandas:

    import pandas as pd

    df = pd.read_json("gs://data-analytics-demos/churn/chat_transcripts.json", lines=True)


    Also, I tried:

    file_path = "https://storage.googleapis.com/data-analytics-demos/churn/chat_transcripts.json"

    Continue reading...

Compartilhe esta Página