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

  • SEARCH
  • Home
  • 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 7885173
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T04:59:33+00:00 2026-06-03T04:59:33+00:00

I am trying to re-index a pandas DataFrame object, like so, From: a b

  • 0

I am trying to re-index a pandas DataFrame object, like so,

From:
            a   b   c
        0   1   2   3
        1  10  11  12
        2  20  21  22

To :
           b   c
       1   2   3
      10  11  12
      20  21  22

I am going about this as shown below and am getting the wrong answer. Any clues on how to do this?

>>> col = ['a','b','c']
>>> data = DataFrame([[1,2,3],[10,11,12],[20,21,22]],columns=col)
>>> data
    a   b   c
0   1   2   3
1  10  11  12
2  20  21  22
>>> idx2 = data.a.values
>>> idx2
array([ 1, 10, 20], dtype=int64)
>>> data2 = DataFrame(data,index=idx2,columns=col[1:])
>>> data2
     b   c
1   11  12
10 NaN NaN
20 NaN NaN

Any idea why this is happening?

  • 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-03T04:59:35+00:00Added an answer on June 3, 2026 at 4:59 am

    Why don’t you simply use set_index method?

    In : col = ['a','b','c']
    
    In : data = DataFrame([[1,2,3],[10,11,12],[20,21,22]],columns=col)
    
    In : data
    Out:
        a   b   c
    0   1   2   3
    1  10  11  12
    2  20  21  22
    
    In : data2 = data.set_index('a')
    
    In : data2
    Out:
         b   c
    a
    1    2   3
    10  11  12
    20  21  22
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a value I am trying to index that looks like this: Test
So I am trying to remove index.php from address using this manual: http://dev.lohv.eu/1/user_guide/general/urls.html Atm
I'm trying to append /index.html to some folder paths in a list like this:
Trying like this Url.Action(Index, Home, new { page = 5 }) is giving me
I am trying to index data from database. I am doing that successfully. But
I am getting the following errors when i am trying to index the SVN
I am trying to find an index of a given object in my linked
I'm trying to index data from a database in Solr using the DIH. So
Is this possible? Here's what I'm trying: public ActionResult Index() { dynamic p =
This is my first time trying Pandas. I think I have a reasonable use

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.