When pandas dataframe row and column header have the same name

hello. In the case that a dataframe has a column that bears the same name as a row, which does the computer take as default.

Hey @rayolufadeju,

It really depends on what syntax you use. Let’s look at an example dataframe:

>>> df
   a  b
b  1  4
c  2  5
d  3  6

We’ll use brackets select data:

>>> df['b']
b    4
c    5
d    6
Name: b, dtype: object

You can see that we got a series with three items, the column b.

Now, let’s use the loc[] syntax:

>>> df.loc['b']
a    1
b    4
Name: b, dtype: object 

We get a series with two items, the row b.

As you can see, depending on the context, there are different defaults. If there’s a particular syntax you’re interested in, please let me know and I’d be happy to help you on this.

2 Likes