Last active
September 16, 2024 02:22
-
-
Save GuiMarthe/bf6d0f33853bc985bab94165f41f299f to your computer and use it in GitHub Desktop.
We love pandas tm dataframe making functions. You will be missed.
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 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