case

Functions to deal with snake_case columns

Snake Case Column Names


source

replace_parentheses

 replace_parentheses (s)

Replaces __x__ by (x) in string s.

test_eq(replace_parentheses('hi__there__'), 'hi_(there)')
test_eq(replace_parentheses('hi__there____bye__'), 'hi_(there)_(bye)')

source

snake2words

 snake2words (s)

Return properly capitalized version of snake_case string s

test_eq(snake2words('hi_bye__min__'), 'Hi Bye (min)')

source

replace_acronyms

 replace_acronyms (s)

Replaces acronyms in s by its capitalized version.

Edit the acronyms list as you wish.

acronyms = ['MAE', 'RMSE', 'R2']
test_eq(replace_acronyms('foo mae Rmse r2'), 'foo MAE RMSE R2')
test_eq(replace_acronyms(['foo mae Rmse', 'rmse bar']), ['foo MAE RMSE', 'RMSE bar'])
acronyms.append('X2YZ')
test_eq(replace_acronyms(['foo mae Rmse X2Yz', 'rmse bar']), ['foo MAE RMSE X2YZ', 'RMSE bar'])
test_eq(replace_acronyms('foomae'), 'foomae')

source

if_instance

 if_instance (fun, t, x)

source

snake2words_replace_acronyms

 snake2words_replace_acronyms (x)

source

snake2words_replace_acronyms_if_str

 snake2words_replace_acronyms_if_str (x)

DataFrame.rename2words

 DataFrame.rename2words (rename_index_name=True, rename_column_name=True)

Renames columns in snake_case to Words.

df = pd.DataFrame({'var_x': range(3), 'mae__s__': range(3)}, index=pd.Index(range(3), name='index__m__'))
df.rename2words()
Var X MAE (s)
Index (m)
0 0 0
1 1 1
2 2 2
dummydf().rename2words()
Col 1 Col 2
0 100 a
1 101 b
2 102 c
3 103 d
4 104 e

source

PxLabeler

 PxLabeler ()

Behaves like a dictionary from snake_case –> Snake Case.

test_eq(px_labeler['foo'], 'Foo')
test_eq(px_labeler['position__m__'], 'Position (m)')

Set the labels plotly argument to px_labeler.

df = pd.DataFrame({'time__s__': range(10), 'position__m__': range(10), 'speed__m/s__': 10*[1]})
fig = express.scatter(df,x='time__s__', y='position__m__', labels=px_labeler)
fig.show()