英文:
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", ""]}
)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论