Skip to content

Instantly share code, notes, and snippets.

@AdrianoPereira
Created July 13, 2023 13:50
Show Gist options
  • Save AdrianoPereira/1f5ca8ae989dbc30c0cfa9417f566dd5 to your computer and use it in GitHub Desktop.
Save AdrianoPereira/1f5ca8ae989dbc30c0cfa9417f566dd5 to your computer and use it in GitHub Desktop.
# Read the GRIB file into a DataFrame
grib_df = spark.read.format("binaryFile").option("pathGlobFilter", "*.grb").load("/path/to/grib/file.grb")
# Define a function to read the GRIB file using cfgrib
def read_grib_file(file_path):
with cfgrib.open_file(file_path) as ds:
# Read the GRIB data into a pandas DataFrame
grib_data = ds.to_dataframe()
return grib_data
# Read the GRIB file using the defined function
grib_data = grib_df.rdd.map(lambda row: read_grib_file(row.path)).collect()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment