Package: tocase
Functionalitytocaseleverages theregexlibrary to convert your strings into any case.SetupTo install the package run the following command:pipinstalltocaseOnce installed, import thefor_stringsif you want to use the basic API to recase strings. Import thefor_pandasmodules to use the pandas API to recase column names and column values.importtocase.tocase.for_strings.ToCaseasToCaseimporttocase.tocase.for_pandasUsageCamelIt is a naming convention where the first letter in compound words is capitalized, except for the first one.# Example with simple stringTocase("camel-case").camel()# ==> camelCaseTocase("camel case").camel()# ==> camelCaseConstantIt is a naming convention where all letters in compound words are capitalized. Words are joined with an underscore.# Example with simple stringTocase("Constant-case").constant()# ==> CONSTANT_CASETocase("constant Case").constant()# ==> CONSTANT_CASEDotIt is a naming convention where all letters in compound words are lowercased. Words are joined with a dot.# Example with simple stringTocase("Dot-case").dot()# ==> dot.caseTocase("dot Case").dot()# ==> dot.caseHeaderIt is a naming convention where the first letter in compound words is capitalized. Words are joined by a dash.# Example with simple stringTocase("Header-case").header()# ==> Header-CaseTocase("header Case").header()# ==> Header-CaseKebabIt is a naming convention where all letters in compound words are lowercased. Words are joined by a dash.# Example with simple stringTocase("Kebab-case").kebab()# ==> kebab-caseTocase("kebab Case").kebab()# ==> kebab-casePascalIt is a naming convention where the first letter in compound words is capitalized.# Example with simple stringTocase("Pascal-case").pascal()# ==> PascalCaseTocase("pascal Case").pascal()# ==> PascalCaseSnakeIt is a naming convention where all letters in compound words are lowercased. Words are joined by an underscore.# Example with simple stringTocase("Snake-case").snake()# ==> snake_caseTocase("snake Case").snake()# ==> snake_caseTitleIt is a naming convention where the first letter in compound words is capitalized. Words are separated by a space.# Example with simple stringTocase("Title-case").title()# ==> "Title Case"Tocase("title Case").title()# ==> "Title Case"With pandas DataFramesYou can work with pandas DataFrame to recase columns names or column values. See the following examples with fake data.columns=["first name","last name","age","family doctor"]values=[["Jules","Otti",35,"Dr James Porter"],["Marie","Curie",22,"Dr Vicky Laporte"],["Marc","El Bichon",35,"Dr Hyde Frank"]]data=pd.DataFrame(data=values,columns=columns)To recase columns names, use thecolDataFrame accessor and the appropriate recasing function described above.print(data)"""first name last name  age   family doctor0      Jules      Otti   35   DrJamesPorter1      Marie     Curie   22  DrVickyLaporte2       Marc  ElBichon   35     DrHydeFrank"""print(data.col.constant())"""FIRST_NAME LAST_NAME  AGE   FAMILY_DOCTOR0      Jules      Otti   35   DrJamesPorter1      Marie     Curie   22  DrVickyLaporte2       Marc  ElBichon   35     DrHydeFrank"""To recase columns values, use thevalDataFrame accessor, the appropriate recasing function described above with a list of the columns to be processed.columns_to_process=["first name","last name","family doctor"]print(data.val.constant(columns_to_process))"""first name  last name  age     family doctor0      JULES       OTTI   35   DR_JAMES_PORTER1      MARIE      CURIE   22  DR_VICKY_LAPORTE2       MARC  EL_BICHON   35     DR_HYDE_FRANK"""For developersClone or download the repository on your machine. If you havepoetryinstalled just run the following command to restore the working environment:poetryinstallIf you don't havepoetryyou can usepipand therequirements.txtfile:pipinstall-rrequirements.txtTo run tests, stay at the root of the directory and run:pytest-vAll contributions are more than welcome. So feel free to to make a PR.AuthorFaouzi Braza