Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9145169
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:26:50+00:00 2026-06-17T10:26:50+00:00

I have a dataframe df with duplicate columns: (I need duplicate columns dataframe, which

  • 0

I have a dataframe df with duplicate columns: (I need duplicate columns dataframe, which will be passed as a parameter to matplotlib to plot, so the columns’ name and content might be same or different)

>>> df
                                         PE     RT    Ttl_mkv      PE
STK_ID    RPT_Date                                  
11_STK79  20130115  41.932  2.744   3629.155  41.932
21_STK58  20130115  14.223  0.048  30302.324  14.223
22_STK229 20130115  22.436  0.350  15968.313  22.436
23_STK34  20130115 -63.252  0.663   4168.189 -63.252

I can get the second column by : df[df.columns[1]] ,

>>> df[df.columns[1]]
STK_ID     RPT_Date
11_STK79   20130115    2.744
21_STK58   20130115    0.048
22_STK229  20130115    0.350
23_STK34   20130115    0.663

but if I want to get the first column by df[df.columns[0]] , it will give :

>>> df[df.columns[0]]
                                   PE      PE
STK_ID    RPT_Date                
11_STK79  20130115  41.932  41.932
21_STK58  20130115  14.223  14.223
22_STK229 20130115  22.436  22.436
23_STK34  20130115 -63.252 -63.252

Which one has two columns? That will make my application down for the application just wants the first column but Pandas give 1st & 4th column! Is it a bug or it is designed as this on purpose ? How to bypass this issue ?

My pandas version is 0.8.1 .

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T10:26:52+00:00Added an answer on June 17, 2026 at 10:26 am

    I dont really understand why you need to two columns with the same name, avoiding it would probably be the best.

    But to answer your question, this would return only 1 of the ‘PE’ columns:

    df.T.drop_duplicates().T.PE
    
    STK_ID     RPT_Date
    11_STK79   20130115    41.932
    21_STK58   20130115    14.223
    22_STK229  20130115    22.436
    23_STK34   20130115   -63.252
    Name: PE
    

    or:

    df.T.ix[0].T
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have need to name columns of a data.frame with duplicate names. inside of
If I have a dataframe that has columns that include the same name, is
Possible Duplicate: Drop Columns R Data frame Let's say I have a dataframe with
Possible Duplicate: Drop Columns R Data frame Suppose, I have the following dataframe, and
I have a data frame with 50000 rows and 200 columns. There are duplicate
I have a dataframe with distances df<-data.frame(site.x=c(A,A,A,B,B,C), site.y=c(B,C,D,C,D,D),Distance=c(67,57,64,60,67,60)) I need to convert this to
I have a dataframe with some numeric columns. Some row has a 0 value
I have a dataframe with over 200 columns. The issue is as they were
I have a dataframe which contains some duplicates. I want to sum rows of
I have a large dataframe. For some purposes I need to do the following:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.