I have a pandas DataFrame with the beginnings of postal codes distinguished by regions in following form:
region A 385
region B 656 - 659
I need to unwrap the data with dash, so it will be:
region B 656, 657, 658, 659
My code
postcodes.iloc[:,1] = postcodes.iloc[:,1].apply(lambda x: x.split('—'))
def unwrap_codes(row):
row = row['Postcode begins with']
if len(row) > 1:
for x, y in row:
while x != y:
row.append(x=+1)
postcodes['Unwraped'] = postcodes.apply(unwrap_codes, axis=1)
returns a ValueError: ('too many values to unpack (expected 2)' Could you please help me to handle the error?