I have a requirement to read and process .DBF
File in PySpark but I didn’t get any library that how can I read that like we read the CSV, JSON, Parquet or other file.
Please help to read this file.
I’m block at starting level only. after creating spark session how to read the .DBF
file.
dbfread
is the library available in python to read dbf
files. But I need to read in PySpark and not only using Python.
Code :
from pyspark.sql import SparkSession
spark = (SparkSession.builder
.master("local[*]")
.appName("dbf-file-read")
.getOrCreate())
Now How to Start with .DBF
File Read?
2
Answers
It seems that it is not possible to load .dbf using pyspark.
Try to use this python "dbfread" package to read and convert your data to the dict format.
Then utilize spark.createdataframe() function to switch from dict to DF. After that, you can apply pyspark transformations on your data (make use of workers).
Install this python library for read DBF file into python.
pip install dbfread
This code will read DBF file file and return as python dictionary.
Now convert the dict to spark dataframe
sample code: