Python Forum
weird number output - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Data Science (https://python-forum.io/forum-44.html)
+--- Thread: weird number output (/thread-23052.html)

Pages: 1 2


weird number output - karlito - Dec-09-2019

Hi,
I have already converted the column x (see picture) into float64 but the output is really "weird" specially on excel but with Pandas it still saves many numbers after the dot. How can I manage to have just 2 numbers after the dot?. Thks

# Excel
-10.949.600.833.333.300
-21.294.745.833.333.300
-21.679.851.666.666.600
-10.070.619.666.666.600
-216.481.025
-14.975.645.666.666.600
-19.041.302.499.999.900
-14.257.553.333.333.300
-15.648.158.333.333.300

####

# Pandas
-10949.600833
-21294.745833
-21679.851667
-100706.196667
-21648.102500
-149756.456667
-19041.302500
-14257.553333
-15648.158333



RE: weird number output - DeaD_EyE - Dec-09-2019

Without code, it's a guessing game.


RE: weird number output - karlito - Dec-09-2019

(Dec-09-2019, 07:28 AM)DeaD_EyE Wrote: Without code, it's a guessing game.
Hi,
I don't think code will be needed here (correct em if I'm wrong, cause there is a lot of steps) ... I read the file with Pandas, converted the column into float and did some operations on the column and now I have this output.


RE: weird number output - perfringo - Dec-09-2019

(Dec-09-2019, 07:38 AM)karlito Wrote: I don't think code will be needed here (correct em if I'm wrong, cause there is a lot of steps) ... I read the file with Pandas, converted the column into float and did some operations on the column and now I have this output.

So you read file which formatting we don't know, you converted it into float in a way we don't know, you performed some operations on floats we know nothing about and now you want to know why you have this output......

Maybe there are some graduates of Hogwarts School of Witchcraft and Wizardry who are able to answer this kind of question. I am not graduate of said school (and I see that DeaD_EyE is neither) Big Grin


RE: weird number output - karlito - Dec-11-2019

(Dec-09-2019, 02:00 PM)perfringo Wrote:
(Dec-09-2019, 07:38 AM)karlito Wrote: I don't think code will be needed here (correct em if I'm wrong, cause there is a lot of steps) ... I read the file with Pandas, converted the column into float and did some operations on the column and now I have this output.

So you read file which formatting we don't know, you converted it into float in a way we don't know, you performed some operations on floats we know nothing about and now you want to know why you have this output......

Maybe there are some graduates of Hogwarts School of Witchcraft and Wizardry who are able to answer this kind of question. I am not graduate of said school (and I see that DeaD_EyE is neither) Big Grin

Hi,
sorry guys ... I think I was wrong. so how can I edit my post or should post a new thread?


RE: weird number output - karlito - Dec-12-2019

(Dec-09-2019, 07:28 AM)DeaD_EyE Wrote: Without code, it's a guessing game.
Hi,
I've posted an edited Thread about this issue. please follow the link if you want to help.


RE: weird number output - sandeep_ganga - Dec-12-2019

try if round helps here,


source:trim_numbers.csv

a
-10949.600833
-21294.745833
-21679.851667
-100706.196667
-21648.102500
-149756.456667
-19041.302500
-14257.553333
-15648.158333

import pandas as pd

test = pd.read_csv('trim_numbers.csv', sep=",", index_col=False)
blankIndex=[''] * len(test)
test.index=blankIndex
test.columns = test.columns.str.lower() 

'''
print(test.astype(float))
print(test.astype(int))
print(((test.astype(int)-test.astype(float))*100).astype(int)/100)
print(test.astype(int)-((test.astype(int)-test.astype(float))*100).astype(int)/100)
'''


print(test['a'].dtype)


print('---------------')

print(test['a'])
test['a']=test['a'].round(2)
print(test['a'])
Best Regards,
Sandeep

GANGA SANDEEP KUMAR


RE: weird number output - karlito - Dec-12-2019

(Dec-12-2019, 08:44 AM)sandeep_ganga Wrote: try if round helps here,


source:trim_numbers.csv

a
-10949.600833
-21294.745833
-21679.851667
-100706.196667
-21648.102500
-149756.456667
-19041.302500
-14257.553333
-15648.158333

import pandas as pd

test = pd.read_csv('trim_numbers.csv', sep=",", index_col=False)
blankIndex=[''] * len(test)
test.index=blankIndex
test.columns = test.columns.str.lower() 

'''
print(test.astype(float))
print(test.astype(int))
print(((test.astype(int)-test.astype(float))*100).astype(int)/100)
print(test.astype(int)-((test.astype(int)-test.astype(float))*100).astype(int)/100)
'''


print(test['a'].dtype)


print('---------------')

print(test['a'])
test['a']=test['a'].round(2)
print(test['a'])
Best Regards,
Sandeep

GANGA SANDEEP KUMAR

Thanks Sandeep,
it does help but I still have these format [Image: 304NMGj]


RE: weird number output - perfringo - Dec-12-2019

Isn’t it somehow cell formatting issue? 30.12 and 6.96? Other numbers seem to be too large for displaying as date.


RE: weird number output - karlito - Dec-12-2019

(Dec-12-2019, 02:07 PM)perfringo Wrote: Isn’t it somehow cell formatting issue? 30.12 and 6.96? Other numbers seem to be too large for displaying as date.

You mean in Excel?