Convert column to number

1,777 views
Skip to first unread message

Salem Ababneh

unread,
May 29, 2018, 7:42:45 AM5/29/18
to OpenRefine
Hello amazing community.

I'm learning so much from the community, and I really appreciate everything.

I just want to know how can I change a column from a General type to Number type, in order to sort it as number from Smaller to Largest.

Because I'm trying to transform the column to number by 'toNumber(value)' and it gives:


Thanks again :)

Ettore Rizza

unread,
May 29, 2018, 7:54:30 AM5/29/18
to OpenRefine
Weird, since you use the right formula. What is your version of OpenRefine and your operating system?

By the way: It's a very bad idea to try to turn a phone into a number. A phone number is by essence a string (you do not do calculations on phone numbers). By transforming 078654 in number, you will lose the leading zero, it will become 78654.

Salem Ababneh

unread,
May 29, 2018, 7:58:21 AM5/29/18
to OpenRefine
I'm using the latest OpenRefine 3.0, and my operating system is Windows 10.

I'm trying to change it to number because it is not sorting to number, neither smallest to largest or largest to smallest are working. So I thought that the problem is that it is General type. (I'm trying to do sorting so I can try the solution you gave me in Topic Link.

Ettore Rizza

unread,
May 29, 2018, 8:01:34 AM5/29/18
to OpenRefine
I guess your phone numbers must contain invisible characters that do not please OpenRefine. Could you click on "edit" in any of your cells containing the phone numbers and tell me if you see anything special?

Salem Ababneh

unread,
May 29, 2018, 8:05:27 AM5/29/18
to OpenRefine
Ettore! You did it again!, it appears that there was a space on each one, and I did a trim and it worked perfectly. Thanks again!

Ettore Rizza

unread,
May 29, 2018, 8:10:46 AM5/29/18
to OpenRefine
You're welcome, but I think this is a bug. Normally, a trim is done automatically when using toNumber().

Salem Ababneh

unread,
May 29, 2018, 8:13:56 AM5/29/18
to OpenRefine
Oh okay, I thought it was a bug. I think because OpenRefine 3.0 is still in beta stage.

Thanks again.

Thad Guidry

unread,
May 29, 2018, 10:21:36 AM5/29/18
to openr...@googlegroups.com
Ettore,

Can you confirm the bug, and if so, open an issue and mark for 3.0 milestone ?  Thanks !

-Thad

--
You received this message because you are subscribed to the Google Groups "OpenRefine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openrefine+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ettore RIZZA

unread,
May 29, 2018, 10:26:30 AM5/29/18
to openrefine
@thad : I am also on Windows 10 and I cannot reproduce the issue. In any case not with normal blank spaces before or after the string to transform in number. It must be another type of non-printable character.

To unsubscribe from this group and stop receiving emails from it, send an email to openrefine+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "OpenRefine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openrefine+unsubscribe@googlegroups.com.

Thad Guidry

unread,
May 29, 2018, 10:41:28 AM5/29/18
to openr...@googlegroups.com
Its &nbsp  - Non Breaking Spaces


   return CharMatcher.WHITESPACE.trimFrom((String) s1);


We should trim &nbsp as well, ideally...BUT ! there's a huge downside that many folks know and use OpenRefine trim() and have confidence it does not throw away &nbsp's.

But in the case of conversions, we should be throwing them away.
We probably just need to add functionality for throwing away &nbsp's for toNumber() and perhaps toDate() and a few others ?


But I would not add handling &nbsp directly for trim() because of the past expectations of not dealing with &nbsp's

-Thad

Salem Ababneh

unread,
May 30, 2018, 3:24:33 AM5/30/18
to OpenRefine
Thank you guys, if you want me to share with you the file please tell me.

Thanks again
Reply all
Reply to author
Forward
0 new messages