在Python中打印时,如何不截断长int/float

在Python中打印时,如何不截断长int/float,python,printing,long-integer,Python,Printing,Long Integer,我有一个长int,我不希望在打印它或将它转换为字符串时它被截断 以下操作不起作用: import pandas as pd b = pd.Series({"playerid": 544911367940993}, dtype='float64') print("%s" % b['playerid']) print(str(b['playerid']) jreback找到的解决方案: In [75]: b.apply(lambda x: x.__repr__()) Out[75]: playe

我有一个长int,我不希望在打印它或将它转换为字符串时它被截断

以下操作不起作用:

import pandas as pd
b = pd.Series({"playerid": 544911367940993}, dtype='float64')
print("%s" % b['playerid'])
print(str(b['playerid'])

jreback找到的解决方案:

In [75]: b.apply(lambda x: x.__repr__())
Out[75]: 
playerid    544911367940993.0
dtype: object

In [77]: b.apply(lambda x: "%.0f" % x)
Out[77]: 
playerid    544911367940993
dtype: object

打印不会截断长整数,也不会使用
%s”
进行格式设置:


因此,我猜将它传递到
pd.Series()
和/或通过写入
b['playerid']
从该对象获取它会进行任何截断。

如果您只是想像在OP中那样打印它,您可以使用
%d
格式字符串

In [5]: print('%d' % b['playerid'])
544911367940993
还可以使用format()函数:

In [25]: x = '{:.0f}'.format(b['playerid'])
In [26]: x
Out[26]: '544911367940993'

您的解决方案比我以前通过jreback找到的解决方案要优雅得多,我接受您的回答!
In [25]: x = '{:.0f}'.format(b['playerid'])
In [26]: x
Out[26]: '544911367940993'