Created
July 27, 2024 09:11
-
-
Save ianrussel/c3465feeecf0605a2caf3823816224ad to your computer and use it in GitHub Desktop.
Seatable XLSX file
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
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