基于多关键字对数据帧上的行进行排序

2024-05-19 12:23:58 发布

您现在位置:Python中文网/ 问答频道 /正文

嗨,我正在学习数据科学,正在制作一个大数据公司列表,其中包含一些属性。你知道吗

目前我的数据帧,data,看起来像这样。你知道吗

    company_url company tag_line    product data
0   https://angel.co/billguard  BillGuard   The fastest smartest way to track your spendin...   BillGuard is a personal finance security app t...   New York City · Financial Services · Security ...
1   https://angel.co/tradesparq Tradesparq  The world's largest social network for global ...   Tradesparq is Alibaba.com meets LinkedIn. Trad...   Shanghai · B2B · Marketplaces · Big Data · Soc...
2   https://angel.co/sidewalk   Sidewalk    Hoovers (D&B) for the social era    Sidewalk helps companies close more sales to s...   New York City · Lead Generation · Big Data · S...
3   https://angel.co/pangia Pangia  The Internet of Things Platform: Big data mana...   We collect and manage data from sensors embedd...   San Francisco · SaaS · Clean Technology · Big ...
4   https://angel.co/thinknum   Thinknum    Financial Data Analysis Thinknum is a powerful web platform to value c...   New York City · Enterprise Software · Financia...

我想用某些关键字(比如“bigdata”)对“data”列进行排序,并用这些行创建一个新的dataframe。你知道吗

我想先找到合适的行,然后,把它们放到一个列表中,然后根据行列表对数据框、数据进行排序,但是第一部分出现了一个错误。你知道吗

我的代码:

comp_rows = []
a = ['Data','Analytics','Machine Learning','Deep','Mining']

for count, item in enumerate(data.data):
    if any(x in item for x in a):
        comp_rows.append(count)

错误:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-174-afeee7d3d179> in <module>()
      3 
      4 for count, item in enumerate(data.data):
----> 5     if any(x in item for x in a):
      6         comp_rows.append(count)

<ipython-input-174-afeee7d3d179> in <genexpr>((x,))
      3 
      4 for count, item in enumerate(data.data):
----> 5     if any(x in item for x in a):
      6         comp_rows.append(count)

TypeError: argument of type 'float' is not iterable

有人能帮我吗?你知道吗


Tags: 数据inhttps列表fordataiscount
1条回答
网友
1楼 · 发布于 2024-05-19 12:23:58

如果您的data.data是一个字符串列表,但是在那里找到了一个浮点值,那么它就可以工作了。尝试替换
if any(x in item for x in a):if any(x in str(item) for x in a):

相关问题 更多 >