如何通过Python或Tableau prep过滤csv文件中的位置?

问题描述 投票:-1回答:1

我有一个20K Tweets的csv文件,该文件的一列是用户的位置。这些地点来自世界各地,但只有美国对我们很重要。数据集的屏幕截图如下:enter image description here

如何通过Python或Tableau Prep筛选此文件,以仅保留其用户所在的州为美国的行? (删除所有其位置都不来自美国的行)

python pandas tableau data-cleaning preprocessor
1个回答
0
投票
import pandas as pd 

df = pd.DataFrame(['Usa','Australia','Asia','Africa','Europe'],columns = ['continent'])


# make a list of word you want to filter 

list_ = ['Asia','Europe','Africa']


# now you can use pandas isin functionality to filter the data that you want

df.loc[df['continent'].isin(list_)]

#op
    continent
2   Asia
3   Africa
4   Europe
© www.soinside.com 2019 - 2024. All rights reserved.