About 164,000 results
Open links in new tab
  1. python - How do I sort a dictionary by value? - Stack Overflow

    Mar 5, 2009 · As proposed in 2012 by Raymond Hettinger (cf. mail on python-dev with subject "More compact dictionaries with faster iteration") and now (in 2016) announced in a mail by …

  2. python - How to sort pandas dataframe by one column - Stack …

    If you want to sort by two columns, pass a list of column labels to sort_values with the column labels ordered according to sort priority. If you use df.sort_values(['2', '0']) , the result would be …

  3. How to sort a pandas dataFrame by two or more columns?

    Jun 17, 2013 · Say, given df below, you want to sort by 'date' and 'value' but treat 'date' like datetime values even though they are strings. A straightforward sort_values with two sort by …

  4. Sorting a Python list by two fields - Stack Overflow

    employees.sort(key = lambda x:x[1]) employees.sort(key = lambda x:x[0]) We can also use .sort with lambda 2 times because python sort is in place and stable. This will first sort the list …

  5. python - Sorting by absolute value without changing the data

    May 27, 2015 · I'd love to see a version of this that can do this across multiple indices, so that, e.g., if index1 can be either "Fruit" or "Vegetables", and index2 is any fruit or vegetable, and …

  6. python - Sort a list by multiple attributes? - Stack Overflow

    Nov 20, 2010 · Here's one way: You basically re-write your sort function to take a list of sort functions, each sort function compares the attributes you want to test, on each sort test, you …

  7. python, sort descending dataframe with pandas - Stack Overflow

    I'm trying to sort a dataframe by descending. I put 'False' in the ascending argument, but my order is still ascending. My code is: from pandas import DataFrame import pandas as pd d = {'one':[2...

  8. What is the cleanest way to do a sort plus uniq on a Python list?

    Note that x[0] (or operator.itemgetter(0)) won't work if you're using a key argument to groupby to decide some alternate equality between elements for uniqueness purposes (roughly the …

  9. python - Sorting a set of values - Stack Overflow

    Jul 3, 2013 · s = {10, 39, 3} s_list = list(s) s_list.sort() # sort in-place # [3, 10, 39] Since Python 3.7, dicts keep insertion order. So if you want to order a set but still want to be able to do …

  10. python - What is the difference between sort_values and …

    sort_values is meant to sort by the values of columns; sort_index is meant to sort by the index labels (or a specific level of the index, or the column labels when axis=1) Previously, sort …

Refresh