Avatar ·

Task: converting a string from camel case to snake case

📁 python

Need to convert a string from camel case to snake case, add the ability to change the separator. I solved the problem, but would like to know which way is more correct to solve it.

def camel_to_snake(str, sep=' '):    snake_register = ''    for i in str:        if i.isupper():            snake_register += sep + i.lower()        else:            snake_register += i    print(snake_register.lstrip(sep))camel_register = 'ThisIsCamelCased'camel_to_snake(camel_regist                    
Avatar ·

If a column with dates has the datetime64 data type, then Pandas will take care of sorting the values along the X axis itself.

Example:

In [105]: df = pd.DataFrame({""DT"": pd.date_range('2021-01-01', periods=20), ""val"": np.random.randint(100, size=20)}).sample(frac=1)In [106]: dfOut[106]:           DT  val15 2021-01-16   712  2021-01-03   23                                

Log in to leave an answer

Blogs