pandas (Python)阅读并使用Java BigInteger/大数 [英] Pandas (Python) reading and working on Java BigInteger/ large numbers

查看:220
本文介绍了 pandas (Python)阅读并使用Java BigInteger/大数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据文件( csv ),其中包含 Nilsimsa 哈希值.其中一些将长达80个字符.我希望在Python中阅读它们以进行数据分析任务.有没有一种方法可以在python中导入数据而不会丢失信息?

I have a data file (csv) with Nilsimsa hash values. Some of them would have as long as 80 characters. I wish to read them in Python for data analysis tasks. Is there a way to import the data in python without information loss?

我已经尝试了注释中建议的实现,但对我而言不起作用. csv 文件中的示例数据为:77241756221441762028881402092817125017724447303212139981668021711613168152184106

I have tried the implementations proposed in the comments but that does not work for me. Example data in csv file would be: 77241756221441762028881402092817125017724447303212139981668021711613168152184106

推荐答案

如@JohnE在他的回答中所解释的那样,在使用Pandas读取大量数字时,我们不会丢失任何信息.它们存储为dtype=object,要对其进行数值计算,我们需要将此数据转换为数值类型.

As explained by @JohnE in his answer that we do not lose any information while reading big numbers using Pandas. They are stored as dtype=object, to make numerical computation on them we need to transform this data into numerical type.

对于系列:

我们必须将map(func)应用于数据框中的序列:

We have to apply the map(func) to the series in the dataframe:

df['columnName'].map(int)

整个数据框:

如果由于某种原因,我们的整个数据框由带有dtype=object的列组成,我们看一下applymap(func)

If for some reason, our entire dataframe is composed of columns with dtype=object, we look at applymap(func)

来自熊猫的文档:

DataFrame.applymap(func):将一个函数应用于旨在逐元素操作的DataFrame,即像对DataFrame中的每个序列进行map(func,series)

DataFrame.applymap(func): Apply a function to a DataFrame that is intended to operate elementwise, i.e. like doing map(func, series) for each series in the DataFrame

因此要转换数据框中的所有列:

so to transform all columns in dataframe:

 df.applymap(int)

这篇关于 pandas (Python)阅读并使用Java BigInteger/大数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆