0

I have created a data frame using the code below:

bins = [['0', '50'], ['0', '100'], ['0', '150'], ['0', '200'], ['0', '250'], ['0', '300'], ['0', '350'], ['0', '400']]
bins = pd.DataFrame(bins, columns = ['start', 'end'])
bins['range'] = bins[['start', 'end']].agg('-'.join, axis=1)
bins.start = pd.to_numeric(bins.start)
bins.end = pd.to_numeric(bins.end)

data frame looks like this:

   start  end    range
0      0   50     0-50
1     50  100   50-100
2    100  150  100-150
3    150  200  150-200
4    200  250  200-250
5    250  300  250-300
6    300  350  300-350
7    350  400  350-400

I am trying to add a new column named 'axis' that will include the string 'up to' and then the value from 'end' column, e.g. row 1 'axis' column will show 'up to 50' and row 2 will show 'up to 100'

What is the best way of doing this?

Thanks in advance

MeganCole
  • 39
  • 1
  • 6

1 Answers1

4

Use:

df['axis'] = 'up to ' + df['end'].astype(str)
jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252