3

I have tried to choose a column to be an index of a data frame. The examples I've seen so far suggests to use the method set_index(), but it doesn't work in my case. I use python 3.7.0

import pandas as pd

df = pd.DataFrame({'Fruit' : ['Apples','Oranges'],
                   'Amount': [ 1, 17 ]})

df.set_index('Fruit')


print(df1)

The output that I get is

       Fruit  Amount
0   'Apples'       1
1  'Oranges'      17

The output I want would be something like

              Amount
     Fruit  
    'Apples'       1
   'Oranges'      17
Jacob Arén
  • 41
  • 1
  • 4

0 Answers0