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?
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?
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