Skip to content

Instantly share code, notes, and snippets.

@do-me
Created January 30, 2025 08:09
Show Gist options
  • Save do-me/dc8877049c2c074df3c7d8e707adf138 to your computer and use it in GitHub Desktop.
Save do-me/dc8877049c2c074df3c7d8e707adf138 to your computer and use it in GitHub Desktop.
Trim embedding decimals from pandas
import pandas as pd
import json
import gzip
# Load data
df = pd.read_json("your_file.json.gz")
# Round embeddings to 4 decimal places
df["embeddings"] = df["embeddings"].apply(lambda emb: [round(e, 4) for e in emb])
# Save to a gzipped JSON file
with gzip.open("your_file__4_dec.json.gz", "wt", encoding="utf-8") as f:
json.dump(df.to_dict(orient="records"), f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment