pandas 将'NA'转换为NaN [英] Pandas Convert 'NA' to NaN

查看:266
本文介绍了 pandas 将'NA'转换为NaN的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚拿起熊猫来从事生物学研究中的一些数据分析工作.原来我正在分析的一种蛋白质称为"NA".

I just picked up Pandas to do with some data analysis work in my biology research. Turns out one of the proteins I'm analyzing is called 'NA'.

我有一个矩阵标题,其标题对上成对地包含"HA,M1,M2,NA,NP ...",并且与行标题"相同(对于可能读过这篇文章的生物学家,我正在与流感).

I have a matrix with pairwise 'HA, M1, M2, NA, NP...' on the column headers, and the same as "row headers" (for the biologists who might read this, I'm working with influenza).

当我直接从CSV文件将数据导入Pandas时,它将读取行标题"为"HA,M1,M2 ...",然后将NA读取为NaN.有什么办法可以阻止这种情况?列标题很好-'HA,M1,M2,NA,NP等...

When I import the data into Pandas directly from a CSV file, it reads the "row headers" as 'HA, M1, M2...' and then NA gets read as NaN. Is there any way to stop this? The column headers are fine - 'HA, M1, M2, NA, NP etc...'

推荐答案

以这种方式关闭NaN检测:pd.read_csv(filename, keep_default_na=False)

Turn off NaN detection this way: pd.read_csv(filename, keep_default_na=False)

我最初建议na_filter=False,它可以完成工作.但是,如果我理解下面杰夫的评论,这是一个更干净的解决方案.

I originally suggested na_filter=False, which gets the job done. But, if I understand Jeff's comments below, this is a cleaner solution.

示例:

In [1]: pd.read_csv('test')
Out[1]:[4]: pd.read_csv('test', keep_default_na=False)
Out[4]:1   2
2   3

这篇关于 pandas 将'NA'转换为NaN的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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