[new feature] auto covert possible column to numerical
wavefancy opened this issue · 5 comments
wavefancy commented
change:
echo '1 2' | pawk 'int(f[0])<=1'
to:
echo '1 2' | pawk 'f[0]<=1'
We do not need to make the conversion every time, especially when we have many operations.
Thanks much!
alecthomas commented
How would this work exactly? The fields are just Python strings and the code is just normal Python.
wavefancy commented
By fastnumbers package:
In [5]: from fastnumbers import fast_float, float as fnfloat
In [6]: [fast_float(x) for x in ['12','bad','Na']]
Out[6]: [12.0, 'bad', 'Na']
Or by try/catch except for testing:
https://code-maven.com/slides/python-programming/is-number
A discussion on stack
overflow:https://stackoverflow.com/questions/354038/how-do-i-check-if-a-string-is-a-number-float
Best regards
Wallace
…On Sat, Mar 3, 2018 at 7:53 AM, Alec Thomas ***@***.***> wrote:
How would this work exactly? The fields are just Python strings and the
code is just normal Python.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#13 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ABZncgdyDH10oZim0PBT2O4Kde1mQc2Zks5tapJPgaJpZM4Sa40O>
.
alecthomas commented
Sorry, I should have been clearer. I more meant how would that work at a holistic level. eg. If integer strings are converted to integers then this would fail: ','.join(f)
I don't think it's a good idea, but I'd be interested in any ideas.
wavefancy commented
','.jion(map(str,f)) would work then.
…On Sat, Mar 3, 2018 at 9:35 AM Alec Thomas ***@***.***> wrote:
Sorry, I should have been clearer. I more meant how would that work at a
holistic level. eg. If integer strings are converted to integers then this
would fail: ','.join(f)
I don't think it's a good idea, but I'd be interested in any ideas.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#13 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ABZncvzGn6hOSjUC-mSxGPx43IjHapbxks5taqodgaJpZM4Sa40O>
.
alecthomas commented
Right but then you've solved one annoyance and introduced another...