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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:19:42+00:00 2026-06-13T11:19:42+00:00

Suppose I have a Pandas dataframe df has columns a,b,c,d…z . And I want

  • 0

Suppose I have a Pandas dataframe df has columns a,b,c,d…z . And I want to: df.groupby('a').apply(my_func()) for columns d-z, while leave column 'b' & 'c' unchanged . How to do that ?

I notice Pandas can apply different function to different column by passing a dict . But I have a long column list and just want parameters to set or tip to simply tell Pandas to bypass some columns and apply my_func() to rest of columns ? (Otherwise I have to build a long dict)

  • 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-13T11:19:43+00:00Added an answer on June 13, 2026 at 11:19 am

    One simple (and general) approach is to create a view of the dataframe with the subset you are interested in (or, stated for your case, a view with all columns except the ones you want to ignore), and then use APPLY for that view.

    In [116]: df
    Out[116]: 
         a  b         c  d        f
    0  one  3  0.493808  a      bob
    1  two  8  0.150585  b    alice
    2  one  6  0.641816  c  michael
    3  two  5  0.935653  d      joe
    4  one  1  0.521159  e     kate
    

    Use your favorite methods to create the view you need. You could select a range of columns like so df_view = df.ix[:,'b':'d'], but the following might be more useful for your scenario:

    #I want all columns except two 
    cols = df.columns.tolist()    
    mycols = [x for x in cols if not x in ['a','f']]
    df_view = df[mycols]
    

    Apply your function to that view. (Note this doesn’t yet change anything in df.)

    In [158]: df_view.apply(lambda x: x /2)
    Out[158]: 
       b         c   d
    0  1  0.246904  20
    1  4  0.075293  25
    2  3  0.320908  28
    3  2  0.467827  28
    4  0  0.260579  24
    

    Update the df using update()

    In [156]: df.update(df_view.apply(lambda x: x/2))
    
    In [157]: df
    Out[157]: 
         a  b         c   d        f
    0  one  1  0.246904  20      bob
    1  two  4  0.075293  25    alice
    2  one  3  0.320908  28  michael
    3  two  2  0.467827  28      joe
    4  one  0  0.260579  24     kate
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have a DataFrame with 100k rows and a column name . I
Suppose I have a DataFrame which has a subindex structure like the following, with
Suppose I have a pandas data frame df : I want to calculate the
Suppose I have a table called Companies that has a DepartmentID column. There's also
Suppose I have a pandas DF with 'A','B','C' as column name A B C
Suppose I have two h:inputText components. I want to bind both of the text
Suppose I have 3 language: en , tc , sc , I want to
Suppose we have a numbered circle. We want to go from point A to
suppose we have this next sample code: while(some condition){ lock1.lock(); . . } the
Suppose I have two pages: - page 1 uses jquery mobile and has a

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.