natural-sort

Natural sort a data frame column in pandas [duplicate]

蹲街弑〆低调 提交于 2020-06-26 13:57:16
问题 This question already has answers here : Naturally sorting Pandas DataFrame (2 answers) Closed 2 years ago . I would like to apply a natural sort order to a column in a pandas DataFrame . The columns that I would like to sort might contain duplicates. I have seen the related Naturally sorting Pandas DataFrame question, however it was concerning sorting the index, not any column. Example df = pd.DataFrame({'a': ['a22', 'a20', 'a1', 'a10', 'a3', 'a1', 'a11'], 'b': ['b5', 'b2', 'b11', 'b22', 'b4

Sort and list the files from a directory in numeric order

核能气质少年 提交于 2020-05-14 19:14:04
问题 This is my folder structure. /home/files/encounters 9-22-11-0.jpg .. /home/files/encounters 9-22-11-[n].jpg puts Dir.glob("/home/files/*.jpg")[0] When i execute the above code, it displayed the sixth file (index 5 => /home/files/encounters 9-22-11-5.jpg), but actually i need the output as first file(index 0 => /home/files/encounters 9-22-11-0.jpg) How can i sort the files as user defined sorting order?. like When i tried.. ..[0] => /home/files/encounters 9-22-11-5.jpg ..[1] => /home/files

Java File list same order like Window explorer

血红的双手。 提交于 2020-02-25 02:50:26
问题 I am using the code below to get file list ordering: (like window explorer) package com.codnix.quickpdfgenerator.testing; import java.io.File; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.Iterator; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; public class FileListOrder { public static void main(String args[]) { //huge test data set ;) File folder = new File("C:\\Users\

how to sort varchar numeric columns by DESC or ASC?

主宰稳场 提交于 2020-01-15 05:34:26
问题 I write ... ORDER BY column ASC but my column is VARCHAR and it sorts wrong like 1, 10, 2 , instead of 1, 2, 10 . How can I do it to sort like 1, 2, 10 ? 回答1: order by cast(column as float) Notes: Assumed you only have numbers in the columns. No "fish" or "bicycle" empty strings CAST to zero Edit: For MySQL. You can not cast to float order by cast(column as decimal(38,10)) 回答2: You can cast to int... order by cast(column as int) DEMO DECLARE @q as table( name varchar(50), columnn varchar(10)

Naturally sort a list moving alphanumeric values to the end

送分小仙女□ 提交于 2020-01-14 11:36:41
问题 I have a list of strings I want to natural sort: c = ['0', '1', '10', '11', '2', '2Y', '3', '3Y', '4', '4Y', '5', '5Y', '6', '7', '8', '9', '9Y'] In addition to natural sort, I want to move all entries that are not pure number strings to the end. My expected output is this: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '2Y', '3Y', '4Y', '5Y', '9Y'] Do note that everything has to be natsorted - even the alphanumeric strings. I know I can use the natsort package to get what I

Naturally sort a list moving alphanumeric values to the end

无人久伴 提交于 2020-01-14 11:36:26
问题 I have a list of strings I want to natural sort: c = ['0', '1', '10', '11', '2', '2Y', '3', '3Y', '4', '4Y', '5', '5Y', '6', '7', '8', '9', '9Y'] In addition to natural sort, I want to move all entries that are not pure number strings to the end. My expected output is this: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '2Y', '3Y', '4Y', '5Y', '9Y'] Do note that everything has to be natsorted - even the alphanumeric strings. I know I can use the natsort package to get what I

Substituting value in empty field after using split_part

情到浓时终转凉″ 提交于 2020-01-03 14:15:34
问题 I have two columns, id integer and version text . I am trying to convert the strings in version into integers so that I may select the maximum (most recent) version of the id. However, the the first instance of the id stores itself as the version . Example: id | version ---+-------- 10 | '10' as opposed to: id | version ---+-------- 10 | '10-0' Additional rows follow the convention id: 10, version: 10-1. Etc. How can I accomplish this? I have tried split_part() and cast as int . However,

Natural sort for SQL Server?

天涯浪子 提交于 2020-01-01 09:14:07
问题 I have a column that is typically only numbers (sometimes it's letters, but that's not important). How can I make it natural sort? Currently sorts like this: {1,10,11,12,2,3,4,5,6,7,8,9} I want it to sort like this: {1,2,3,4,5,6,7,8,9,10,11,12} 回答1: IsNumeric is "broken", ISNUMERIC(CHAR(13)) returns 1 and CAST will fail. Use ISNUMERIC(textval + 'e0'). Final code: ORDER BY PropertyName, CASE ISNUMERIC(MixedField + 'e0') WHEN 1 THEN 0 ELSE 1 END, -- letters after numbers CASE ISNUMERIC

Version sort (with alphas, betas, etc.) in ruby

荒凉一梦 提交于 2019-12-30 16:42:13
问题 How do I sort a list of versions in Ruby? I've seen stuff about natural sort, but this is a step beyond that. Input is a bunch of strings like this: input = ['10.0.0b12', '10.0.0b3', '10.0.0a2', '9.0.10', '9.0.3'] I can almost do it with the naturally gem: require 'naturally' Naturally.sort(input) => ["9.0.3", "9.0.10", "10.0.0a2", "10.0.0b12", "10.0.0b3"] Problem: 10.0.0b3 is sorted after 10.0.0b12; 10.0.0b3 should be first. Anyone have a way that works? Other languages are helpful too! 回答1:

Version sort (with alphas, betas, etc.) in ruby

旧街凉风 提交于 2019-12-30 16:40:06
问题 How do I sort a list of versions in Ruby? I've seen stuff about natural sort, but this is a step beyond that. Input is a bunch of strings like this: input = ['10.0.0b12', '10.0.0b3', '10.0.0a2', '9.0.10', '9.0.3'] I can almost do it with the naturally gem: require 'naturally' Naturally.sort(input) => ["9.0.3", "9.0.10", "10.0.0a2", "10.0.0b12", "10.0.0b3"] Problem: 10.0.0b3 is sorted after 10.0.0b12; 10.0.0b3 should be first. Anyone have a way that works? Other languages are helpful too! 回答1: