简体   繁体   English

Python Pandas read_csv float64 到字符串

[英]Python Pandas read_csv float64 to string

I'm reading below CSV file as read_csv我正在阅读下面的 CSV 文件作为read_csv

day,order,variant,variant_name
2020-05-04,OR_001,1000000548952,Product1
2020-05-04,OR_001,1000000056488,Product4
2020-05-04,OR_002,1000000528985,Product2

When I read this in a dataframe and then print the variant column当我在 dataframe 中阅读此内容然后打印变体列时

print(df_SalesOrders["variant"])

I get the below output.我得到下面的 output。

0     1.000001e+12
1     1.000000e+12
2     1.000001e+12

Could someone please let me know how can I preserve the original number which I believe is treated as float64.有人可以让我知道如何保留我认为被视为 float64 的原始数字。

I tried the below code however that didn't help.我尝试了下面的代码,但是没有帮助。

myarr = df_SalesOrders.variant.astype(str)

Any help is much appreciated.任何帮助深表感谢。 Thanks.谢谢。

You need to add you change to your dataframe您需要将更改添加到您的 dataframe

df_SalesOrders.variant = df_SalesOrders.variant.astype('int64')

Please call请打电话

pd.options.display.float_format = '{:,.4f}'.format 
df

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Python Pandas read_csv dtype 无法将“字符串”转换为“float64” - Python Pandas read_csv dtype fails to covert "string" to "float64" python pandas read_csv boolean as string - python pandas read_csv boolean as string 熊猫read_csv low_memory和dtype选项。 TypeError:根据规则“安全”,无法将数组从dtype('O')转换为dtype('float64') - Pandas read_csv low_memory and dtype options. TypeError: Cannot cast array from dtype('O') to dtype('float64') according to the rule 'safe' float64 与 pandas to_csv - float64 with pandas to_csv 在 pandas read_csv 中将百分比字符串转换为浮点数 - Convert percent string to float in pandas read_csv 在Python中二进制化float64 Pandas Dataframe - Binarize a float64 Pandas Dataframe in Python 熊猫read_csv将字符串转换为日期时间并保存到数据库Python - Pandas read_csv converting string to datetime and saving to database Python Python Pandas:在包含数字和字符串元素的列中将类型从 float 更改为 float64 - Python Pandas: Change type from float to float64 in a column which contains both numerical and string elements CSV 'A$ 12,000.00' 从字符串到浮动 pandas 和 read_csv - CSV ‘A$ 12,000.00’ from string to float with pandas and read_csv 熊猫read_csv不将字符串转换为日期 - pandas read_csv not converting string to date
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM