'hi__there__'), 'hi_(there)')
test_eq(replace_parentheses('hi__there____bye__'), 'hi_(there)_(bye)') test_eq(replace_parentheses(
case
Functions to deal with snake_case columns
Snake Case Column Names
replace_parentheses
replace_parentheses (s)
Replaces __x__
by (x)
in string s.
snake2words
snake2words (s)
Return properly capitalized version of snake_case string s
'hi_bye__min__'), 'Hi Bye (min)') test_eq(snake2words(
replace_acronyms
replace_acronyms (s)
Replaces acronyms in s by its capitalized version.
Edit the acronyms list as you wish.
acronyms = ['MAE', 'RMSE', 'R2']
'foo mae Rmse r2'), 'foo MAE RMSE R2') test_eq(replace_acronyms(
'foo mae Rmse', 'rmse bar']), ['foo MAE RMSE', 'RMSE bar']) test_eq(replace_acronyms([
'X2YZ')
acronyms.append('foo mae Rmse X2Yz', 'rmse bar']), ['foo MAE RMSE X2YZ', 'RMSE bar']) test_eq(replace_acronyms([
'foomae'), 'foomae') test_eq(replace_acronyms(
if_instance
if_instance (fun, t, x)
snake2words_replace_acronyms
snake2words_replace_acronyms (x)
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.
= pd.DataFrame({'var_x': range(3), 'mae__s__': range(3)}, index=pd.Index(range(3), name='index__m__'))
df 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 |
PxLabeler
PxLabeler ()
Behaves like a dictionary from snake_case –> Snake Case.
'foo'], 'Foo')
test_eq(px_labeler['position__m__'], 'Position (m)') test_eq(px_labeler[
Set the labels
plotly argument to px_labeler
.
= pd.DataFrame({'time__s__': range(10), 'position__m__': range(10), 'speed__m/s__': 10*[1]})
df = express.scatter(df,x='time__s__', y='position__m__', labels=px_labeler)
fig fig.show()