Python Forum

Full Version: weird number output
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
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
Without code, it's a guessing game.
(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.
(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
(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?
(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.
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
(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]
Isn’t it somehow cell formatting issue? 30.12 and 6.96? Other numbers seem to be too large for displaying as date.
(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?
Pages: 1 2