Skip to content

Instantly share code, notes, and snippets.

@zhensongren
zhensongren / import_csv_endpoint.py
Created August 25, 2025 20:02
import_csv_endpoint
@app.post("/campaigns/import_csv")
async def import_csv(
file: UploadFile = File(..., description="CSV with headers; includes parameters + objectives"),
meta_json: Optional[str] = Form(None, description='Tiny JSON, e.g. {"objectives":[{"name":"y","direction":"max"}],"batch_size":3}')
):
# 1) Load CSV
try:
text = (await file.read()).decode("utf-8")
df = pd.read_csv(StringIO(text))
# app/main.py
from io import StringIO, BytesIO
from typing import Dict, List, Tuple, Optional
from uuid import uuid4
import hashlib
import pandas as pd
from fastapi import FastAPI, UploadFile, File, Form, HTTPException
from fastapi.responses import StreamingResponse, JSONResponse
# ---- BayBE (verified API)
@zhensongren
zhensongren / excel_to_sqlite.py
Last active August 14, 2025 21:40
Excel/Sheets ➜ export UTF-8 CSV in Git ➜ FastAPI reads & validates on startup ➜ serves responses.
# Avoid reading formulas/macros; target a single sheet
df = pd.read_excel("source.xlsx", sheet_name="data", engine="openpyxl")
df.to_csv("export.csv", index=False)
import pandas as pd
import pyarrow as pa
import pyarrow.parquet as pq
# Read CSV with explicit dtypes when possible
df = pd.read_csv(
# %%
import pandas as pd
import numpy as np
from darts import TimeSeries
from darts.models import NBEATSModel
from darts.metrics import mape
from darts.dataprocessing.transformers import Scaler
# %%
import numpy as np
@zhensongren
zhensongren / plot_partial_cross_correlation.py
Created July 16, 2025 04:11
plot_partial_cross_correlation
import numpy as np
import matplotlib.pyplot as plt
from statsmodels.regression.linear_model import OLS
from statsmodels.tools.tools import add_constant
def plot_partial_cross_correlation(x, y, max_lag=20, title=None):
"""
Plot partial cross-correlation (PCC) between time series x and y.
Parameters:
# %% [markdown]
# A 4×4 grid of scatter plots
# Each showing the relationship between lagged ts1 (predictor) and ts2 (target)
# %%
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
from darts import TimeSeries
@zhensongren
zhensongren / ask_llama
Created September 10, 2023 13:59
A full-stack application for asking questions again internal documents
https://github.com/run-llama/sec-insights/issues/9
https://www.secinsights.ai/conversation/fa6614b9-ccac-4b01-a94b-779a404e6141
Sure, here's the questionnaire in English:
Do you encounter situations in your daily work that require handling a large amount of data?
a. Yes, I frequently deal with large volumes of data.
b. Sometimes, I handle some data.
c. Rarely, I am not heavily involved in data processing.
d. No, I don't work with data.
How familiar are you with AI (Artificial Intelligence) and data science?
a. Completely unfamiliar, I would like to start from the basics.
@zhensongren
zhensongren / uninstall_python3.MD
Last active February 27, 2025 03:38
How to uninstall python3 from Ubuntu

To list all python versions in default locations

ls /usr/bin/python*

To remove just python3 package

sudo apt-get remove python3.5

plus it's dependent packages

sudo apt-get remove --auto-remove python3.5

plus configuration and/or data files of python3

sudo apt-get purge python3.5