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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:07:26+00:00 2026-06-15T12:07:26+00:00

I’m reading Python for Data Analysis by Wes Mckinney, but I was surprised by

  • 0

I’m reading Python for Data Analysis by Wes Mckinney, but I was surprised by this data manipulation. You can see all the procedure here but I will try to summarize it here. Assume you have something like this:

In [133]: agg_counts = by_tz_os.size().unstack().fillna(0)
    Out[133]:
    a                 Not Windows   Windows
    tz                  245          276
    Africa/Cairo         0            3
    Africa/Casablanca    0            1
    Africa/Ceuta         0            2
    Africa/Johannesburg  0            1
    Africa/Lusaka        0            1
    America/Anchorage    4            1
    ...

tz means time zone and Not Windows and Windows are categories extracted from the User Agent in the original data, so we can see that there are 3 Windows users and 0 Non-windows users in Africa/Cairo from the data collected.

Then in order to get “the top overall time zones” we have:

In [134]: indexer = agg_counts.sum(1).argsort()
Out[134]:
tz
                                  24
Africa/Cairo                      20
Africa/Casablanca                 21
Africa/Ceuta                      92
Africa/Johannesburg               87
Africa/Lusaka                     53
America/Anchorage                 54
America/Argentina/Buenos_Aires    57
America/Argentina/Cordoba         26
America/Argentina/Mendoza         55
America/Bogota                    62
...

So at that point, I would have thought that according to the documentation I was summing over columns (in sum(1)) and then sorting according to the result showing arguments (as usual in argsort). First of all, I’m not sure what does it mean “columns” in the context of this series because sum(1) is actually summing Not Windows and Windows users keeping that value in the same row as its time zone. Furthermore, I can’t see a correlation between argsort values and agg_counts. For example, Pacific/Auckland has an “argsort value” (in In[134]) of 0 and it only has a sum of 11 Windows and Not Windows users. Asia/Harbin has an argsort value of 1 and appears with a sum of 3 Windows and Not Windows users.

Can someone explain to me what is going on there? Obviously I’m misunderstanding something.

  • 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-15T12:07:28+00:00Added an answer on June 15, 2026 at 12:07 pm

    sum(1) means sum over axis = 1. The terminology comes from numpy.

    For a 2+ dimensional object, the 0-axis refers to the rows. Summing over the 0-axis means summing over the rows, which amounts to summing “vertically” (when looking at the table).

    The 1-axis refers to the columns. Summing over the 1-axis means summing over the columns, which amounts to summing “horizontally”.


    numpy.argsort returns an array of indices which tell you how to sort an array. For example:

    In [72]: import numpy as np
    
    In [73]: x = np.array([521, 3, 1, 2, 1, 1, 5])
    
    In [74]: np.argsort(x)
    Out[74]: array([2, 4, 5, 3, 1, 6, 0])
    

    The 2 in the array returned by np.argsort means the smallest value in x is x[2], which equals 1. The next smallest is x[4] which is also 1. And so on.

    If we define

    totals = df.sum(1)
    print(totals)
    # tz                     521
    # Africa/Cairo             3
    # Africa/Casablanca        1
    # Africa/Ceuta             2
    # Africa/Johannesburg      1
    # Africa/Lusaka            1
    # America/Anchorage        5
    

    then totals.argsort() is argsorting the values [521, 3, 1, 2, 1, 1, 5]. We’ve seen the result; it is the same as numpy.argsort:

    [2, 4, 5, 3, 1, 6, 0]
    

    These values are simply made into a Series, with the same index as totals:

    print(totals.argsort())
    # tz                     2
    # Africa/Cairo           4
    # Africa/Casablanca      5
    # Africa/Ceuta           3
    # Africa/Johannesburg    1
    # Africa/Lusaka          6
    # America/Anchorage      0
    

    Associating the totals.index with this argsort indices does not appear have intrinsic meaning, but if you compute totals[totals.argsort()] you see the rows of totals in sorted order:

    print(totals[totals.argsort()])
    # Africa/Casablanca        1
    # Africa/Johannesburg      1
    # Africa/Lusaka            1
    # Africa/Ceuta             2
    # Africa/Cairo             3
    # America/Anchorage        5
    # tz                     521
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
Does anyone know how can I replace this 2 symbol below from the string
I want to construct a data frame in an Rcpp function, but when I
Let's say I'm outputting a post title and in our database, it's Hello Y’all
I am reading a book about Javascript and jQuery and using one of the
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text

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.