Skip to content

Instantly share code, notes, and snippets.

@cristlee
Forked from LouisAmon/avro_to_dataframe.py
Created July 30, 2019 08:14
Show Gist options
  • Save cristlee/9f9ef106dcb84642fd74ba538256d071 to your computer and use it in GitHub Desktop.
Save cristlee/9f9ef106dcb84642fd74ba538256d071 to your computer and use it in GitHub Desktop.
Read Avro file from Pandas
import pandas
import fastavro
def avro_df(filepath, encoding):
# Open file stream
with open(filepath, encoding) as fp:
# Configure Avro reader
reader = fastavro.reader(fp)
# Load records in memory
records = [r for r in reader]
# Populate pandas.DataFrame with records
df = pandas.DataFrame.from_records(records)
# Return created DataFrame
return df
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment