sorting

Confirm if column in a pandas dataframe is in a sequential order starting by one

Confirm if column in a pandas dataframe is in a sequential order starting by one Question: Imagine I have the following column on a dataframe: df[‘Col1’] = [1, 2, 3, 4, 6, 5] What would be the best way to confirm if this column is in a sequential order having their lowest value starting with …

Total answers: 2

Can't understand the lambda function inside the sorted() key argument

Can't understand the lambda function inside the sorted() key argument Question: I have to sort a string in this order: All sorted lowercase letters are ahead of uppercase letters. All sorted uppercase letters are ahead of digits. All sorted odd digits are ahead of sorted even digits. For instance, when the input is "Sample6789", the …

Total answers: 2

Merging two Pandas DataFrames based on the sequential order of two columns

Merging two Pandas DataFrames based on the sequential order of two columns Question: I know questions related to this one have been asked multiple times, but I can’t find anything specific this one. I have gone through pandas.pydata.org/docs/user_guide/merging.html but I still can’t find what I need. I have two very large output files that I …

Total answers: 2

in python sort and group by common elements in a list

in python sort and group by common elements in a list Question: I will try to express myself clearly. Would anyone know how to order elements with common values in a list? I made a drawing to explain it better. I have a list with several letters and their two number. ev=((‘A’,(1,2)), (‘M’,(0,40)),(‘S’,(17,32)),(‘Z’,(2,7)),(‘K’,(7,12)),(‘U’,(40,18)),(‘R’,(32,5)),(‘V’,(28,47)),(‘X’,(5,28))) and after …

Total answers: 1

Python pandas sort_values not working properly

Python pandas sort_values not working properly Question: When I try to sort DataFrame by column value and print it white head() function it shows duplicated rows instead of desired result regions = country_features[‘world_region’] happines = [] counts = [] reg = [] for region in regions: hap = country_features.loc[country_features[‘world_region’] == region, ‘happiness_score’].mean() count = len(country_features[country_features[‘world_region’] …

Total answers: 1

How to divide data into three lines?

How to divide data into three lines? Question: I’m making a database for my cadet corps, because our officers’ organisation is a MESS and I want to organise things and I’m making a menu with buttons labeled after each master cadets. To make it aesthetically pleasing, I wanted to split it into three lines, but …

Total answers: 1

Why is this simple Python program not giving the correct output?

Why is this simple Python program not giving the correct output? Question: The challenge is given below: You will be given an array of numbers. You have to sort the odd numbers in ascending order while leaving the even numbers at their original positions. [7, 1] => [1, 7] [5, 8, 6, 3, 4] => …

Total answers: 5

sort list based on dictionary values even with missing keys

sort list based on dictionary values even with missing keys Question: I am trying to sort a list based on dictionary values. The only problem is that if a list contains something that doesn’t exist in the dictionary it wont sort it. here is what I have d = { "hello0" : 0, "hello1" : …

Total answers: 1

How to sort output before writing to JSON

How to sort output before writing to JSON Question: I have a problem with sorting data. When I use the json_dic.sort(key= lambda x: x[‘lastLogonTimestamp’], reverse= False) command I get an error TypeError: ‘<‘ not supported between instances of ‘str’ and ‘list’. When I checked the output with the type() function, I found that I was …

Total answers: 4