sorting

Array Sort by time hh:mm:ss

。_饼干妹妹 提交于 2020-06-08 06:42:08
问题 I am trying to sort the time. but I am unable to sort by time (hh:mm:ss) format. so i have used moments js. my array sort by time not get sorted. how sort array by using maps I have an array of objects: let elements =[ { "id": 1, "date": "02:01:02" }, { "id": 2, "date": "01:01:01" }, { "id": 3, "date": "03:01:01" }, { "id": 4, "date": "04:01:01" } ]; let parsedDates = new Map( elements.map(e =>[["id", "date"],[e.id, moment(e.date, 'hh:mm:ss')]]) ); elements.sort((a, b) => parsedDates.get(a) -

Sorting a pandas DataFrame by the order of a list

时间秒杀一切 提交于 2020-06-08 04:33:12
问题 So I have a pandas DataFrame, df, with columns that represent taxonomical classification (i.e. Kingdom, Phylum, Class etc...) I also have a list of taxonomic labels that correspond to the order I would like the DataFrame to be ordered by. The list looks something like this: class_list=['Gammaproteobacteria', 'Bacteroidetes', 'Negativicutes', 'Clostridia', 'Bacilli', 'Actinobacteria', 'Betaproteobacteria', 'delta/epsilon subdivisions', 'Synergistia', 'Mollicutes', 'Nitrospira', 'Spirochaetia',

Sorting a pandas DataFrame by the order of a list

感情迁移 提交于 2020-06-08 04:31:27
问题 So I have a pandas DataFrame, df, with columns that represent taxonomical classification (i.e. Kingdom, Phylum, Class etc...) I also have a list of taxonomic labels that correspond to the order I would like the DataFrame to be ordered by. The list looks something like this: class_list=['Gammaproteobacteria', 'Bacteroidetes', 'Negativicutes', 'Clostridia', 'Bacilli', 'Actinobacteria', 'Betaproteobacteria', 'delta/epsilon subdivisions', 'Synergistia', 'Mollicutes', 'Nitrospira', 'Spirochaetia',

How can I sort an indirect array with javascript?

假如想象 提交于 2020-06-07 04:51:17
问题 In my project, I need to sort an array that contain index of an other array (it's item). I've search for many hours, but I did not find anyone with my problem. var arr = [1, 4, 3, 4, 5, 6, 7, 8, 9]; function sorting(){ let arr2 = [0, 1, 2, 3, 4, 5, 6, 7, 8]; //sorting code } Now, I want to sort arr2, so when I loop through it with this kind of code (under this paragraph), I access arr with the index in the sorted array (arr2). arr[arr2[i]] My first move was to use arr2.sort(function(a,b){arr

Sorting values in a pandas series in ascending order not working when re-assigned

落爺英雄遲暮 提交于 2020-06-01 05:57:08
问题 I am trying to sort a Pandas Series in ascending order. Top15['HighRenew'].sort_values(ascending=True) Gives me: Country China 1 Russian Federation 1 Canada 1 Germany 1 Italy 1 Spain 1 Brazil 1 South Korea 2.27935 Iran 5.70772 Japan 10.2328 United Kingdom 10.6005 United States 11.571 Australia 11.8108 India 14.9691 France 17.0203 Name: HighRenew, dtype: object The values are in ascending order . However, when I then modify the series in the context of the dataframe : Top15['HighRenew'] =

Top N values in 2d array with duplicates to mask

折月煮酒 提交于 2020-05-31 04:08:19
问题 I have 2d numpy array: arr = np.array([[0.1, 0.1, 0.3, 0.4, 0.5], [0.06, 0.1, 0.1, 0.1, 0.01], [0.24, 0.24, 0.24, 0.24, 0.24], [0.2, 0.25, 0.3, 0.12, 0.02]]) print (arr) [[0.1 0.1 0.3 0.4 0.5 ] [0.06 0.1 0.1 0.1 0.01] [0.24 0.24 0.24 0.24 0.24] [0.2 0.25 0.3 0.12 0.02]] I want filter top N values, so I use argsort : N = 2 arr1 = np.argsort(-arr, kind='mergesort') < N print (arr1) [[False False False True True] [ True False False True False] <- first top 2 are duplicates [ True True False

Sorting Currency in Bootstrap Table

百般思念 提交于 2020-05-30 07:06:27
问题 I want to add the currency sign to my number while making the value remain sortable as a number in my Bootstrap Table (line 30-34; column 4 in the table): for (var p=0; p<variable_data.length; p++){ try{ variable_data[p]["4"] = "$" + Math.round(variable_data[p]["4"]) } catch(e){ } } http://jsfiddle.net/mademoiselletse/s0d1xgzt/ The values with the '$' attached are sorted as strings instead of numbers. All the currency sorting problems I found online pertain to the DataTable and tablesorter()

Sort lines after a certain character in notepad++

家住魔仙堡 提交于 2020-05-29 10:14:08
问题 i have lines that i want to sort from the highest number to the lowest or the opposite so not really an issue exemple from this: steven:class3 | Pounds: 6 ibesom:class1 | Pounds: 125 heller:class1 | Pounds: 13 to this: ibesom:class1 | Pounds: 125 heller:class1 | Pounds: 13 steven:class3 | Pounds: 6 Thank you guys 回答1: For simple sorting tasks you can just rearrange the contents of the line, sort, then return the lines to their original form. This can often be done with simple regular

sort numbers numerically and strings alphabetically in an array of hashes perl

北城余情 提交于 2020-05-29 09:55:45
问题 It's a very easy problem but can't get my way around it. I have an array of hashes. The data structure as follows: my @unsorted = ( { 'key_5' => '14.271 text', # ... }, { 'key_5' => 'text', # ... }, { 'key_5' => '13.271 text', # ... }, { 'key_5' => 'etext', # ... }, ); How can I sort the array based on key_5 of the hash. The string part should be sorted alphabetically. and where the key is number string (format is always like this),it should be sorted numerically (ignoring the string part

PostgreSQL - conditional ordering

◇◆丶佛笑我妖孽 提交于 2020-05-29 07:08:11
问题 I have the following table: key | date | flag -------------------------- 1 now() true 2 now() - 1 hour true 3 now() + 1 hour true 4 now() false 5 now() - 1 hour false 6 now() + 1 hour false I want the following sorting: First, all rows with flag = false . These rows must be sorted with date asc . Then, all other rows ( flag = true ). However, these rows must be sorted with date desc . Is the following query correct? ( select * from test where flag = false order by date asc ) union all (