Power BI:如何使用Python处理/清理字符串数据?
我开始学习Power BI。我在PowerBI中设置了一个数据集,在编辑器中我尝试使用pythonPower BI:如何使用Python处理/清理字符串数据?,python,powerbi,Python,Powerbi,我开始学习Power BI。我在PowerBI中设置了一个数据集,在编辑器中我尝试使用python # 'dataset' holds the input data for this script dataset = dataset['word' in dataset['Title']] 基本上,我想删除列标题中不包含单词“word”的行。有人能帮忙吗 提前感谢使用数据集[~dataset['title'].str.contains('word')],其中~操作员负责处理过程中不属于部分的
# 'dataset' holds the input data for this script
dataset = dataset['word' in dataset['Title']]
基本上,我想删除列标题中不包含单词“word”的行。有人能帮忙吗
提前感谢使用
数据集[~dataset['title'].str.contains('word')]
,其中~
操作员负责处理过程中不属于部分的
示例:结合了PowerBI和Python的功能
让我们看一个虚构的示例,其中包含一些类别的好的、坏的或平庸的电影,以及一个带有ID的列。如果您阅读本文,您将看到如何使用Python在PowerBI中插入示例数据集。这篇文章将向你展示以下程序的所有细节:
如果使用PowerQuery编辑器插入python代码段,如下所示:
# 'dataset' holds the input data for this script
import pandas as pd
df_dataset = pd.DataFrame({'title': {0: 'bad movie',
1: 'mediocre movie',
2: 'bad movie',
3: 'bad movie',
4: 'good movie',
5: 'bad movie',
6: 'bad movie',
7: 'mediocre movie'},
'category': {0: 'drama',
1: 'comedy',
2: 'drama',
3: 'comedy',
4: 'action',
5: 'comedy',
6: 'drama',
7: 'comedy'},
'ID': {0: 32, 1: 46, 2: 96, 3: 25, 4: 83, 5: 78, 6: 36, 7: 96}})
df_notbad = dataset[~dataset['title'].str.contains('bad')]
。。。你会得到这样一张桌子:
# 'dataset' holds the input data for this script
import pandas as pd
df_dataset = pd.DataFrame({'title': {0: 'bad movie',
1: 'mediocre movie',
2: 'bad movie',
3: 'bad movie',
4: 'good movie',
5: 'bad movie',
6: 'bad movie',
7: 'mediocre movie'},
'category': {0: 'drama',
1: 'comedy',
2: 'drama',
3: 'comedy',
4: 'action',
5: 'comedy',
6: 'drama',
7: 'comedy'},
'ID': {0: 32, 1: 46, 2: 96, 3: 25, 4: 83, 5: 78, 6: 36, 7: 96}})
df_notbad = dataset[~dataset['title'].str.contains('bad')]
现在,插入一个新的python代码段,如下所示:
# 'dataset' holds the input data for this script
import pandas as pd
df_dataset = pd.DataFrame({'title': {0: 'bad movie',
1: 'mediocre movie',
2: 'bad movie',
3: 'bad movie',
4: 'good movie',
5: 'bad movie',
6: 'bad movie',
7: 'mediocre movie'},
'category': {0: 'drama',
1: 'comedy',
2: 'drama',
3: 'comedy',
4: 'action',
5: 'comedy',
6: 'drama',
7: 'comedy'},
'ID': {0: 32, 1: 46, 2: 96, 3: 25, 4: 83, 5: 78, 6: 36, 7: 96}})
df_notbad = dataset[~dataset['title'].str.contains('bad')]
。。。将为您提供一个数据集,其中所有带有'bad'
的行都将被删除:
您将不得不查看链接的资源来整理所有的细节,但是如果一些细节不清楚,请不要犹豫让我知道