Trying to make a custom string out of a column. The 'ENTITY' column is either 6 numbers (ex. 184025.0) or 5 numbers (ex. 58063.0). The third to last number before the decimal is always a zero, no matter how many numbers there are. The format should be 000-00, first 3 numbers, dash (which replaces the 0), and the last 2 numbers before the decimal. If the 'ENTITY' only has 5 numbers, a leading zero also needs to be added.
Using the examples above the return values should be:
184025.0 = "184-25"
58063.0 = "058-63"
I tried this but keep getting the original object returned.
cost_centers['length'] = cost_centers['ENTITY'].astype(str)
cost_centers['len'] = cost_centers['length'].str.len()
if cost_centers['len'].equals(7):
cost_centers['COST CENTER'] = '0' + cost_centers['length'][:2] + "-" + cost_centers['length'][2:4]
elif cost_centers['len'].equals(8):
cost_centers['COST CENTER'] = cost_centers['length'].str[:3] + "-" + cost_centers['length'].str[3:]
else:
cost_centers['COST CENTER'] = cost_centers['length']