Last active
March 14, 2022 18:10
-
-
Save TheHumanistX/a36eb7f33cf5f766fbb5b3d83d449982 to your computer and use it in GitHub Desktop.
Move data from JSON-LD files into Pandas dataframes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
################################################################ | |
# The hope is that this script can help you work with JSON-LD # | |
# files (*.ldjson) so that you can move them into Pandas # | |
# DataFrames. # | |
# Email: [email protected] # | |
# Discord: tirwander#1570 # | |
# Twitter: @tirwander # | |
# Crypto: brianfh.eth # | |
################################################################ | |
import json | |
import pandas as pd | |
# Replace FILENAME with the name of your file (and directories if not in working directory) | |
j_data = "FILENAME" | |
with open(j_data, 'r', encoding = 'utf8') as in_f: | |
global data_list | |
for i, line in enumerate(in_f): | |
data = json.loads(line.strip()) | |
if i >= 1 : | |
data_list2 = [data] | |
list2_df = pd.DataFrame(data_list2) | |
list_df = pd.concat([list_df,list2_df], ignore_index = True) | |
if i < 1 : | |
data_list = [data] | |
list_df = pd.DataFrame(data_list) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment