python - PowerBI - Pandas isnull().sum() 索引
问题描述
我在 PowerBI 中运行以下 Python 脚本
# 'dataset' holds the input data for this script
import pandas as pd
import numpy as np
df=pd.DataFrame(np.sum(dataset.isnull(), axis=0),columns=['Null_Values'])
df['Items']=dataset.isnull().index
几点注意事项:
simple
dataset.isnull().sum()
不起作用,因为输出不是 DataFrame,因此在 PowerBI 中作为表不可见如果我从上面的代码片段中删除最后一行,它可以正常工作,但 PowerBI 中的结果表如下所示:
空值
0
0
5
0
4
所以你只能猜测 5 和 4 指的是哪一列。在 Power BI 之外,dataset.isnull().sum()
通常会产生
Null Values
Column A 0
Coulmn B 0
Column C 5
Column D 6
如果我包含代码片段的最后一行,我会收到一个错误
ValueError: Length of values does not match length of index
我只想再添加一列来描述原始列名(列 A、B、C 等)
原始数据集:
Department,OfficeCode,Sales,Target,Staffing,Dotation
South,23,80,100,0.8,10
South,24,67,100,0.78,15
North,33,111,120,0.98,10
South,25,87,100,,15
West,43,45,50,0.98,10
East,53,65,80,0.89,15
North,34,110,120,,10
North,35,112,120,0.96,15
North,36,,120,0.94,10
North,37,98,120,0.85,15
South,26,77,100,0.7,10
East,54,64,80,0.8,15
East,55,,80,,11
West,44,44,50,,14
East,56,,80,0.79,15
West,44,,50,0.9,16
West,45,34,50,0.89,13
South,27,,100,,14
编辑:好的,我已经通过更改最后一行来解决它:
df['Items']=dataset.isnull().index
至
df['Items']=df.index
它所做的是复制索引列,以便可以在 PowerBi 查询编辑器表中看到它。
也许,一个后续问题是如何让 PowerBi 将索引列视为任何其他列并显示它?
解决方案
推荐阅读
- asynchronous - Vue Axios 函数,包括异步函数结果
- sql - SQL - 使用基于两个表的表达式更新表列值
- python - Pandas 数据框 split() 'float' 对象没有属性 'split'
- javascript - ReferenceError:未定义味精+“解析错误:'返回'函数外
- node.js - SendGrid:设置环境变量不起作用
- c++ - 使用 lapacke_dgesv 在 cpp 中求解线性方程组
- android - 在第一种方法完成时改造调用第二种方法
- javascript - USB 条码扫描器重复扫描,无需服务器调用
- regex - Powershell 正则表达式用连字符替换下划线
- python - UBlox NAV_PVT 消息:UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb5