如何通过 Python 或 Tableau prep 过滤 csv 文件中的位置?
How to filter locations in csv file by Python or Tableau prep?
我有一个包含 20K 条推文的 csv 文件,其中一列是用户的位置。这些地点来自世界所有地区,但只有美国各州对我们很重要。数据集截图如下:
如何通过 Python 或 Tableau Prep 过滤此文件以仅保留其用户所在位置为美国的行? (删除所有位置不是来自美国的行)
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
我有一个包含 20K 条推文的 csv 文件,其中一列是用户的位置。这些地点来自世界所有地区,但只有美国各州对我们很重要。数据集截图如下:
如何通过 Python 或 Tableau Prep 过滤此文件以仅保留其用户所在位置为美国的行? (删除所有位置不是来自美国的行)
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