0

I have the following data in a csv file:

name     height       width
apple    [180, 191]   [10, 20]
orange   [50, 130]    [15, 30]

How can I split height and width into: height-min, height-max, width-min, width-max using pandas?

newbie
  • 338
  • 2
  • 12

1 Answers1

-2

You can try the following by splitting on the comma and removing your square brackets.

df['min-height'] = df['height'].str.split(',').str[0].str.strip('[]')
df['max-height'] = df['height'].str.split(',').str[1].str.strip('[]')
df['min-width'] = df['width'].str.split(',').str[0].str.strip('[]')
df['max-width'] = df['width'].str.split(',').str[1].str.strip('[]')

This will create new columns for you

Aidan Donnelly
  • 518
  • 5
  • 16