Data slicing in panda

Screen Link:

My Code: industries = f500.loc[:,“industry”]
industries_type = type(industries)

What I expected to happen:

Replace this line with your code: NOTHING

We are choosing one column i.e. industry. However, the names of the companies are appearing on the left of it. Whenever we used to choose a particular column in Numpy, only 1 column used to be there. For instance, we used, taxi[:,3] in the numpy modules and only 1 column info was available. Nothing left to it was available…

What actually happened:

Replace this line with the output/error

Hi @keswani06,

These names of the companies is not actually a column here, it’s the index of the f500 dataframes. And, correspondingly, it will be the index of any Series object that we’ll create from this dataframe, and it will be always visualize together with the “real” column of a Series. You can check it in this way:


Some dataframes have numbered index (starting from 0), others, like in this case, named index. Indeed, you can always reset the index, assigning any column of a dataframe as its index, if it’s necessary for your task. But it’s important that this column has to have all unique, non-repeating values, to uniquely identify each row.