Skip to content

Instantly share code, notes, and snippets.

View michaelboerman's full-sized avatar

Michael Boerman michaelboerman

View GitHub Profile
library(stringr)
library(dplyr)
convert_feature_name <- function(feature_str) {
# Pattern that matches all possible formats
pattern <- "^rr_(dlnq_\\d{1,3}_\\d{1,3}|dlnq_121plus|not_dlnq)_" %>%
paste0("(dlnq_\\d{1,3}_\\d{1,3}|dlnq_121plus|not_dlnq|term_x)_(\\d{1,3})_(\\d{1,3})")
parts <- str_match(feature_str, pattern)
@michaelboerman
michaelboerman / gpt_transfer.py
Last active November 9, 2023 15:52
for transferring ghat got output
import pandas as pd
import numpy as np
from datetime import datetime
def compare_dataframes(df1, df2):
# Check if one object is a dataframe with datetime64[ns] dtype and the other is a list of strings
if isinstance(df1, pd.DataFrame) and df1.dtypes.all() == 'datetime64[ns]' and isinstance(df2, list):
# Convert the list of strings to datetime64[ns] format
df2_values = np.array([np.datetime64(datetime.strptime(date_str, '%Y-%m-%d')) for date_str in df2])
elif isinstance(df2, pd.DataFrame) and df2.dtypes.all() == 'datetime64[ns]' and isinstance(df1, list):