Skip to content

Instantly share code, notes, and snippets.

@ianrussel
Created July 27, 2024 09:11
Show Gist options
  • Save ianrussel/c3465feeecf0605a2caf3823816224ad to your computer and use it in GitHub Desktop.
Save ianrussel/c3465feeecf0605a2caf3823816224ad to your computer and use it in GitHub Desktop.
Seatable XLSX file
import pandas as pd
import json
import numpy as np
df = pd.read_excel('Analyzer Test Task.xlsx')
# Convert NaN values to None
df = df.replace("", None)
df = df.replace(r'^\s*$', "", regex=True)
df = df.where(pd.notnull(df), None)
df = df.drop(columns=['Column 1'])
# Convert the DataFrame to a list of dictionaries (records)
json_data = df.to_dict(orient='records')
for record in json_data:
for key, value in record.items():
if pd.isna(value):
record[key] = None
# Convert the list of dictionaries to a JSON string with indentation
json_str = json.dumps(json_data, indent=4)
print(json_str)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment