Skip to content

Instantly share code, notes, and snippets.

View nchelaru's full-sized avatar

Nancy Chelaru nchelaru

View GitHub Profile
SELECT name,
type_desc,
create_date,
modify_date
FROM sys.objects
@nchelaru
nchelaru / search_col_mentioned.sql
Created March 12, 2022 19:56
Search table by column name
SELECT c.name AS 'ColumnName',
t.name AS 'TableName'
FROM sys.columns c
JOIN sys.tables t
ON c.object_id = t.object_id
WHERE c.name LIKE '%sci_thin_credit_file_co_app%'
ORDER BY TableName,ColumnName
@nchelaru
nchelaru / list_temp_tables.sql
Created March 12, 2022 19:55
List temp tables
SELECT *
FROM tempdb.sys.objects
ORDER BY create_date DESC
@nchelaru
nchelaru / search_sps.sql
Created March 12, 2022 19:53
Search stored procedures by reference to table name
SELECT Name
FROM sys.procedures
WHERE OBJECT_DEFINITION(OBJECT_ID) LIKE '%TableNameOrWhatever%'
import pandas as pd
import pandera as pa
from pandera import Check, Column, DataFrameSchema
schema = pa.DataFrameSchema(
columns={
"int_column": Column(int),
"float_column": Column(float, Check.greater_than(0)),
"str_column": Column(str, Check.equal_to("a")),
@nchelaru
nchelaru / example_dbt_test.sql
Last active November 27, 2021 23:01
Example file for a test in a dbt project.
{{ config(store_failures = true) }}
-- Test
SELECT *
FROM <table>
WHERE <num_col> > 9
UNION
SELECT *
@nchelaru
nchelaru / search_col.sql
Last active November 21, 2021 18:40
Find all SQL tables containing columns whose header contains a certain string
select * from INFORMATION_SCHEMA.COLUMNS
where COLUMN_NAME like '%clientid%'
order by TABLE_NAME
@nchelaru
nchelaru / merge_multiple_dfs.py
Created August 14, 2020 18:47
Merge multiple dataframes by common column
from functools import partial, reduce
dfs = [df1, df2, df3]
merge = partial(pd.merge, on=['depth', 'profile'], how='outer')
reduce(merge, dfs)
@nchelaru
nchelaru / coalesce_multiple_cols.py
Created August 12, 2020 21:08
Coalesce multiple columns, select value from first non-null instance
## Function
def get_first_non_null(dfrow, columns_to_search):
for c in columns_to_search:
if pd.notnull(dfrow[c]):
return dfrow[c]
return None
## Sample usage:
cols_to_search = ['a1', 'a2', 'a3']
df['A'] = df.apply(lambda x: get_first_non_null(x, cols_to_search), axis=1)
@nchelaru
nchelaru / date_groupby.py
Last active July 9, 2020 02:58
Group rows by custom date period in pandas.
df.groupby(pd.Grouper(key='date', freq='M'))['col2'].sum()