I'm trying to zfill based on 2 column's in my Dataframe. The first column is called unit and it only contains 2 strings, 'Metric' and 'Imperial'.
The second column is called closing which has loads of numbers in it. However if Colum one is metric I need the numbers to zfill to 5 and if its imperial i need to zfill to 4. Example: Metric: 23 needs to become 00023. Imperial: 23 needs to become 0023
Basically, if column one (unit) = Metric, then I want to look at column two (closing) and zfill to 5 if column one (unit) = Imperia, then I want to look at column two (closing) and zfill to 4
This is the current code, however I'm getting the error: 'function' object has no attribute 'astype'
df['Unit'] == 'Metric', df['closing'].replace.astype(str).zfill(5)
df['Unit'] == 'Imperial', df['closing'].replace.astype(str).zfill(4)