import pandas as pd
import re def getNum(x):
"""
科学计数法和字符转浮点数
"""
if re.findall(r'\d+\.\d+E\+',x):
return "%.f" % float(x)
elif x=="C":
return 1
else:
return x df = pd.DataFrame({"x":[2030,1.11002E+11,2030,1.11002E+11,"C"]}) df["x"] = df["x"].astype("str") df["x"] = df["x"].apply(getNum) df["x"] = pd.to_numeric(df["x"]) df["x"] = df["x"].astype("int64")

pandas中一列含有多种数据类型的转换:科学计算法转浮点数、字符映射的更多相关文章

  1. python – 基于pandas中的列中的值从DataFrame中选择行

    如何从基于pandas中某些列的值的DataFrame中选择行?在SQL中我将使用: select * from table where colume_name = some_value. 我试图看看 ...

  2. Pandas中查看列中数据的种类及个数

    Pandas中查看列中数据的种类及个数 读取数据 import pandas as pd import numpy as np filepath = 'your_file_path.csv' data ...

  3. 在 Pandas 中更改列的数据类型

    import pandas as pd import numpy as np a = [['a', '1.2', '4.2'], ['b', '70', '0.03'], ['x', '5', '0' ...

  4. 转载: 黄聪:C#中 Excel列字母与数字的转换

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  5. [No0000107]C#中 Excel列字母与数字的转换

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  6. java和python中的string和int数据类型的转换

    未经允许,禁止转载!!! 在平时写代码的时候经常会用到string和int数据类型的转换 由于java和python在string和int数据类型转换的时候是不一样的 下面总结了java和python ...

  7. 在Pandas中更改列的数据类型【方法总结】

    先看一个非常简单的例子: a = [['a', '1.2', '4.2'], ['b', '70', '0.03'], ['x', '5', '0']] df = pd.DataFrame(a) 有什 ...

  8. [译] Pandas中根据列的值选取多行数据

    # 选取等于某些值的行记录 用 == df.loc[df['column_name'] == some_value] # 选取某列是否是某一类型的数值 用 isin df.loc[df['column ...

  9. pandas中根据列的值选取多行数据

    # 选取等于某些值的行记录 用 == df.loc[df['column_name'] == some_value] # 选取某列是否是某一类型的数值 用 isin df.loc[df['column ...

随机推荐

  1. ORM 之常用重点 ******

    总体介绍orm>>点我 单表查询api汇总  如 distinc(),order_by()  id__gt=1  id__inrange=[ 1,3 ]  左右都包含     设置logg ...

  2. sqler sql 转rest api 源码解析(一)应用的启动入口

    sqler sql 转rest api 的源码还是比较简单的,没有比较复杂的设计,大部分都是基于开源 模块实现的. 说明: 当前的版本为2.0,代码使用go mod 进行包管理,如果本地运行注意gol ...

  3. java数据类型取值范围

    1个字节:boolean, byte 2个字节:short, char 4个字节:int, float 8个字节:long, double 按照我们初学者的理解1byte=8bit,也就是说1个字节可 ...

  4. lua C++ wrapper

    背景 最近在研究lua的c++绑定库,使用过一下几个 luabind 问题:没人维护 https://github.com/vinniefalco/LuaBridge https://github.c ...

  5. 手动制作openstack CentOS 镜像

    https://docs.openstack.org/image-guide/centos-image.html This example shows you how to install a Cen ...

  6. ssh证书免认证登录

    思路: 客户端私钥存放于客户端,/root/.ssh/id_rsa 将客户端公钥存放于要远程控制服务器上:将客户在公钥id_rsa.pub内容追加到 /root/.ssh/authorized_key ...

  7. C# 委托、lambda表达式和事件

    什么是委托?委托就是持有一个或多个方法的对象,并且该对象可以执行,可以传递. using System; using System.Collections.Generic; using System. ...

  8. LNMP, CentOS7.0+Nginx+Mysql5.7+PHP7环境安装

    LNMP代表的就是:Linux系统下Nginx+MySQL+PHP这种网站服务器架构.这里和家分享一下,如何在CentOS 7.0上搭建一个这样的环境,其中软件使用yum方式安装. 进入CentOS ...

  9. ES Terms 聚合数据不确定性

    Elasticsearch是一个分布式的搜索引擎,每个索引都可以有多个分片,用来将一份大索引的数据切分成多个小的物理索引,解决单个索引数据量过大导致的性能问题,另外每个shard还可以配置多个副本,来 ...

  10. 几种always块的形态

    几种always块的形态 1.时钟沿触发与复位触发 2.使能触发 3.预设触发 4.时序寄存器与锁存触发 5.组合逻辑