Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
weird number output
#1
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
Reply
#2
Without code, it's a guessing game.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply
#3
(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.
Reply
#4
(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
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply
#5
(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?
Reply
#6
(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.
Reply
#7
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
Reply
#8
(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]
Reply
#9
Isn’t it somehow cell formatting issue? 30.12 and 6.96? Other numbers seem to be too large for displaying as date.
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply
#10
(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?
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020