Search code examples
pythonpandas

Convert pandas cut operation to a regular string


I get the foll. output from a pandas cut operation:

0        (0, 20]
1        (0, 20]
2        (0, 20]
3        (0, 20]
4        (0, 20]
5        (0, 20]
6        (0, 20]
7        (0, 20]
8        (0, 20]
9        (0, 20]

How can I convert the (0, 20] to 0 - 20?

I am doing this:

.str.replace('(', '').str.replace(']', '').str.replace(',', ' -')

Any better approach?


Solution

  • assuming the output was assigned to a variable cut

    cut.astype(str)
    

    To remove bracketing

    cut.astype(str).str.strip('()[]')