Skip to content

Instantly share code, notes, and snippets.

@GuiMarthe
Last active September 16, 2024 02:22
Show Gist options
  • Save GuiMarthe/bf6d0f33853bc985bab94165f41f299f to your computer and use it in GitHub Desktop.
Save GuiMarthe/bf6d0f33853bc985bab94165f41f299f to your computer and use it in GitHub Desktop.
We love pandas tm dataframe making functions. You will be missed.
import pandas as pd
import numpy as np
def makeMixedDataFrame():
return pd.DataFrame(
{
"A": [0.0, 1.0, 2.0, 3.0, 4.0],
"B": [0.0, 1.0, 0.0, 1.0, 0.0],
"C": pd.Index(["foo1", "foo2", "foo3", "foo4", "foo5"], dtype=object),
"D": pd.date_range("20130101", periods=5),
}
)
def makeDataFrame():
return pd.DataFrame(
np.ones((10, 4)),
columns=pd.Index(list("ABCD"), dtype=object),
index=pd.Index([f"i-{i}" for i in range(10)], dtype=object),
)
def makeTimeDataFrame(nper=None, freq="B") -> pd.DataFrame:
return pd.DataFrame(
np.random.default_rng(2).standard_normal((nper, 4)),
columns=pd.Index(list("ABCD"), dtype=object),
index=pd.date_range("2000-01-01", periods=nper, freq=freq),
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment