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 8562921
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:50:22+00:00 2026-06-11T16:50:22+00:00

I have multilevel dataframe ‘df’ like this : col1 col2 first second a 0

  • 0

I have multilevel dataframe ‘df’ like this :

             col1 col2
first second
a        0    5    5
         1    5    5
         2    5    5
b        0    5    5
         1    5    5

And I want to apply a function func (exp: 'lambda x: x*10') to second, somewhat like :

df.groupby(level='first').second.apply(func)

and result will lokk like:

             col1 col2
first second
a        0    5    5
         10   5    5
         20   5    5
b        0    5    5
         10   5    5

The above command not work for second is not a column, so .second is not accepted by Pandas .

I don’t want to do that by df.reset_index() , blablabla…, then finally df.set_index(). I prefer to do it in one command, How to do ?

  • 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-11T16:50:24+00:00Added an answer on June 11, 2026 at 4:50 pm

    When creating the DataFrame, you could set the MultiIndex as follows:

    df.set_index(['first', 'second'], drop=False)
    

    This way, the index column is not dropped and still accessible for your apply.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a function for a multilevel wordpress menu, but I'd like it
Recursive function for copy of multilevel folder is not working. I have a code
I have standard multi-level menu like this one: <ul id=nav> <li><a href=#>Home</a></li> <li><a href=#>Dropdown</a>
I have a graph of multi-level dependecies like this, and I need to detect
I want to have a map that permits a tree-like behaviour. I want to
I want to delete category from multilevel menu with recursion function. To understand situation
I have an array and I need to sort this array in a multilevel
I want to design a multilevel menu using jQuery. I have already written some
I have run two multilevel logistic regressions using the same predictors, but on two
For development of web services, i have to make multilevel Associative array as follows

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.