sorting

How to alphabetically sort values in a pandas column that is a list

How to alphabetically sort values in a pandas column that is a list Question: I had a question about sorting values in a list in a dataframe. I have sales order data with about 3000 rows. A sales order can contain one or multiple inventory items. I reshaped my data and was able to create …

Total answers: 1

Sort list by dictionary in Python

Sort list by dictionary in Python Question: I want to sort a list by a dictionary, as shown below: The list: L = [‘Jack’, ‘King’, ‘9’, ‘King’, ’10’] The dictionary: D = {0:’Ace’, 1:’King’, 2:’Queen’, 3:’Jack’, 4:’10’, 5:’9′} I want to sort L based on keys of dictionary D, such that the output would be: …

Total answers: 3

issue Letter Grades on python

issue Letter Grades on python Question: Hi all I’m having an issue with my python code. Im new to python im study at tafe and this is one of my task for introduction to python The task is to make a simple code that grades the letters from the total and in oreder for example …

Total answers: 1

Sorting CSV with IP address column in pandas

Sorting CSV with IP address column in pandas Question: I have a CSV file with a column of IP addresses, MAC addresses and some other data. I want to sort all of the data by the IP addresses in ascending order Input: | IP Address | MAC Address | ID | | — | — …

Total answers: 1

Implement sorting by multiple attributes

Implement order definition by multiple attributes Question: I’d like to know how to efficiently sort by object’s multiple attributes. For instance, given class A: def __init__(self, a, b): self.a = a self.b = b def __lt__(self, other): if self.a == other.a: return self.b < other.b return self.a < other.a def __str__(self): return f'{self.__class__.__name__}({self.a}, {self.b})’ A1 …

Total answers: 3

How to give rank on datetime column group by another column with userid in it

How to give rank on datetime column group by another column with userid in it Question: My columns are ID, User_created_date and Customer city while user_created_date is in 2023-01-01 00:01:05+05:30 format now I wanted to know when did the first user was created based on each city and give rank to them based on city …

Total answers: 1

Sort Columns by assigned column

Sort Columns by assigned column Question: I have a following code: import bs4 as bs import requests import yfinance as yf import datetime import pandas as pd import time starttimer = time.time() resp = requests.get(‘http://en.wikipedia.org/wiki/List_of_S%26P_500_companies’) soup = bs.BeautifulSoup(resp.text, ‘lxml’) table = soup.find(‘table’, {‘class’: ‘wikitable sortable’}) tickers = [] for row in table.findAll(‘tr’)[1:]: ticker = row.findAll(‘td’)[0].text …

Total answers: 2

How to sort even/odd numbers separately in a list?

How to sort even/odd numbers separately in a list? Question: I have list with both even and odd numbers. I want to sort the positions with even, odd distinct numbers together. It’s like: s = [5, 6, 4, 7, 11, 14, 12, 1, 3] # 5 7 11 1 3 # 6 4 14 12 …

Total answers: 5

How to sort a queryset based on objects' foreign key by sorted method?

How to sort a queryset based on objects' foreign key by sorted method? Question: I’m happy with the instruction to do sorting: sorted(qs, key=lambda obj: obj.name.lower(), reverse=True) But as I need to sort the queryset by obj’s foreign key’s field. It looks invalid with: (Sort won’t work! The order didn’t change.) sorted(qs, key=lambda obj: obj.fkname.name.lower(), …

Total answers: 1