# Ascending order of float numbers

**URL:** <https://discourse.julialang.org/t/ascending-order-of-float-numbers/82296>\
**Category:** General Usage\
**Tags:** question\
**Created:** [June 6, 2022, 9:29am UTC](https://discourse.julialang.org/t/ascending-order-of-float-numbers/82296 "2022-06-06T09:29:18Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![raman\_kumar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raman_kumar/32/26782_2.png) [@raman\_kumar](https://discourse.julialang.org/u/raman_kumar)\
**Post date:** [June 6, 2022, 9:29am UTC](https://discourse.julialang.org/t/ascending-order-of-float-numbers/82296/1 "2022-06-06T09:29:18Z")

</div>

![image](https://global.discourse-cdn.com/julialang/original/3X/9/1/913bd5d4072be3c20dc67cdfdae5e795f7024669.png)  
I want to get TotalCharges of females in ascending order so that i could plot them, but sort function is not taking care of decimal point in number. 😋 as you can see 102 is coming after 1017. what should i do ?

---

<div class="post-metadata">

**Author:** ![skleinbo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/skleinbo/32/36080_2.png) [@skleinbo](https://discourse.julialang.org/u/skleinbo)\
**Post date:** [June 6, 2022, 9:39am UTC](https://discourse.julialang.org/t/ascending-order-of-float-numbers/82296/2 "2022-06-06T09:39:08Z")

</div>

Read the data as floats in the first place. The blanks `" "` should be `missing`. That’s what it is for.

From where and how are you reading the data?

---

<div class="post-metadata">

**Author:** ![raman\_kumar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raman_kumar/32/26782_2.png) [@raman\_kumar](https://discourse.julialang.org/u/raman_kumar)\
**Post date:** [June 6, 2022, 9:42am UTC](https://discourse.julialang.org/t/ascending-order-of-float-numbers/82296/3 "2022-06-06T09:42:59Z")

</div>

i am using CSV file to read data. blanks were places occupied by Male in gender column so on filtering they got away.

 ![image](https://global.discourse-cdn.com/julialang/original/3X/a/5/a58b9cb1704340787803c277da80e23e27cc6f56.png)

> How to read data as Floats ?? 🥴

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [June 6, 2022, 10:02am UTC](https://discourse.julialang.org/t/ascending-order-of-float-numbers/82296/4 "2022-06-06T10:02:46Z")

</div>

Try

```julia
chercn = CSV.read(...path..., DataFrame; missingstring = ' ')

```

if that doesn’t work just do

```julia
parse(Float64, female.TotalCharges)

```

If that fails you’ll be able to work out what sort of non-numeric data you’ve got in the csv file.

---

<div class="post-metadata">

**Author:** ![skleinbo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/skleinbo/32/36080_2.png) [@skleinbo](https://discourse.julialang.org/u/skleinbo)\
**Post date:** [June 6, 2022, 10:05am UTC](https://discourse.julialang.org/t/ascending-order-of-float-numbers/82296/5 "2022-06-06T10:05:15Z")

</div>

`CSV.jl` is usually very good at determining the proper column type. But you can force it to adopt a certain column type as shown here [Examples · CSV.jl](https://csv.juliadata.org/stable/examples.html#types_example)  
Although you should try Nils’ and my suggestion (below) first.

> blanks were places occupied by Male in gender column so on filtering

Okay, but ideally you would have a `missing` in the full dataframe wherever a value is absent. I suspect it’s because the CSV file has `" "` in those places instead of `""`. But you can customize which values are handled as `missing` [Examples · CSV.jl](https://csv.juliadata.org/stable/examples.html#missing_string_example).  
Can you try loading the file with `CSV.read(pathtofile, DataFrame; missingstring=["", " "])`

---

<div class="post-metadata">

**Author:** ![raman\_kumar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raman_kumar/32/26782_2.png) [@raman\_kumar](https://discourse.julialang.org/u/raman_kumar)\
**Post date:** [June 6, 2022, 11:20am UTC](https://discourse.julialang.org/t/ascending-order-of-float-numbers/82296/6 "2022-06-06T11:20:07Z")

</div>

![image](https://global.discourse-cdn.com/julialang/original/3X/6/1/61725cabae9b547f827e135256eadbf825ba9768.png)

> It is showing error.

```julia
using Plots,DataFrames,CSV
chern=CSV.read(joinpath(dirname("/home/raman/Downloads/"),"a83a246242e4a760c6c4078e93ad481a0fcc66c973fe6a1bec4ff68f85fb9445_Telco-Customer-Churn.csv"),DataFrame ) ;missingstrings=' '
male=filter(:gender => ==("Male"),chern);
female=filter(:gender => ==("Female"),chern);
p1=plot(sort(male.TotalCharges) ,seriestype=:scatter);
sort(female.TotalCharges)
p2=plot(sort(female.TotalCharges) ,seriestype=:scatter, );
plot!(p1,p2)

```

 ![image](https://global.discourse-cdn.com/julialang/original/3X/3/8/38f00417a305b0f4e0d4842c52777ce86bcd0c7c.png)

and

 ![image](https://global.discourse-cdn.com/julialang/original/3X/d/c/dc30e014646c80a805c9f2ee2fd2212e7d934799.png)

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [June 6, 2022, 11:28am UTC](https://discourse.julialang.org/t/ascending-order-of-float-numbers/82296/7 "2022-06-06T11:28:30Z")

</div>

The keyword is `missingstring` (singular), or if you use `missingstrings` (plural) you have to supply a vector of missing strings to match like @skleinbo has shown above.

---

<div class="post-metadata">

**Author:** ![raman\_kumar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raman_kumar/32/26782_2.png) [@raman\_kumar](https://discourse.julialang.org/u/raman_kumar)\
**Post date:** [June 6, 2022, 11:34am UTC](https://discourse.julialang.org/t/ascending-order-of-float-numbers/82296/8 "2022-06-06T11:34:52Z")

</div>

yes now sort function is working fine.

 ![image](https://global.discourse-cdn.com/julialang/original/3X/0/3/032d2afd66dfebaf7ff822cc847a78736454e938.png)

---

<div class="post-metadata">

**Author:** ![raman\_kumar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raman_kumar/32/26782_2.png) [@raman\_kumar](https://discourse.julialang.org/u/raman_kumar)\
**Post date:** [June 6, 2022, 1:52pm UTC](https://discourse.julialang.org/t/ascending-order-of-float-numbers/82296/10 "2022-06-06T13:52:41Z")

</div>

how to calculate the number of females in file ? 😘

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [June 6, 2022, 1:56pm UTC](https://discourse.julialang.org/t/ascending-order-of-float-numbers/82296/11 "2022-06-06T13:56:12Z")

</div>

`sum(chern.Female .== "Female")`

but you might want to look at some introductory Julia and/or DataFrames tutorials which in the medium term is probably vastly more productive than asking loads of relatively basic questions here.
