如何显示空值 pandas

huangapple go评论56阅读模式
英文:

How to show blank values pandas

问题

I have dataframe df has column TX_order, when I tried to sum null values df.isnull().sum(axis=0)
The output was TX_order has 0 null values, however it has blank values. How can I show it or calculate this blank values to can remove it.

如下面的示例所示,TX_order 具有空白值,但在输出中未显示。

df

A header TX_order
First
Second row
Second
Second row
Second
英文:

I have dataframe df has column TX_order, when I tried to sum null values df.isnull().sum(axis=0)
The output was TX_order has 0 null values, however it has blank values. How can I show it or calculate this blank values to can remove it.

As in example below the TX_order has blank values but doesn't appear in the output

df

A header TX_order
First
Second row
Second
Second row
Second

答案1

得分: 1

代码部分不需要翻译,以下是翻译好的内容:

看起来你有空字符串,在使用replace之前尝试将它们替换为isnull/sum

df.replace("", None).isnull().sum() # 默认情况下 `axis=0`

输出:

A header    0
TX_order    3
dtype: int64

使用的输入:

df = pd.DataFrame(
    {"A header": ["First", "Second", "Second", "Second", "Second"],
     "TX_order": ["", "row", "", "row", ""]}
)
英文:

Looks like you have empty strings, try to replace them before isnull/sum :

df.replace("", None).isnull().sum() # `axis=0` by default

Output :

A header    0
TX_order    3
dtype: int64

Input used :

df = pd.DataFrame(
    {"A header": ["First", "Second", "Second", "Second", "Second"],
     "TX_order": ["", "row", "", "row", ""]}
)

huangapple
  • 本文由 发表于 2023年5月11日 19:40:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/76227246.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定