Komplexer verschachtelter JSON. Lassen Sie es sich wie einzelnPython

Python-Programme
Anonymous
 Komplexer verschachtelter JSON. Lassen Sie es sich wie einzeln

Post by Anonymous »

Ich habe eine sehr komplexe verschachtelte JSON -Datei und habe das folgende Skript verwendet, um zu sehen, wie die Daten aussehen. Br />

Code: Select all

from ayx import Package,Alteryx
import pandas as pd
import json
from flatten_json import flatten
from pandas.io.json import json_normalize
def load_json_file(file_path):
"""
Loads a JSON file and returns the data as a Python object.

Args:
file_path (str): The path to the JSON file.

Returns:
dict or list: The data loaded from the JSON file, or None if an error occurs.
"""
try:
with open(file_path, 'r') as file:
data = json.load(file)
return data
except FileNotFoundError:
print(f"Error: File not found at {file_path}")
return None
except json.JSONDecodeError:
print(f"Error: Invalid JSON format in {file_path}")
return None
except Exception as e:
print(f"An unexpected error occurred: {e}")
return None

# Example usage:
file_path = r'FileName1.json'
data = load_json_file(file_path)
flat_json = flatten(data)
df = pd.DataFrame([flat_json])
print(df1)
Alteryx.write(df1,1)
Dies generiert 1 Zeile mit rund 15.000 Spalten in Alteryx . Jeder einzelne Datenwert wird als Spalte behandelt. Die Datenwerte sollten Zeilen und die Spaltennamen als Spaltennamen sein.>

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post