嗨,我在学习数据科学,我正试图从一个大数据公司名单上的公司在各个行业。
我有一个大数据公司的行号列表,名为comp_rows。 现在,我正试图根据行号创建一个新的数据框架,其中包含经过筛选的公司。在这里,我需要添加行到现有的数据帧,但我得到了一个错误。有人能帮忙吗?
我的数据帧是这样的。
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_comp = DataFrame(data=None,columns=['company_url','company','tag_line','product','data'])
for count, item in enumerate(data.iterrows()):
for number in comp_rows:
if int(count) == int(number):
bigdata_comp.append(item)
错误:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-234-1e4ea9bd9faa> in <module>()
4 for number in comp_rows:
5 if int(count) == int(number):
----> 6 bigdata_comp.append(item)
7
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas/core/frame.pyc in append(self, other, ignore_index, verify_integrity)
3814 from pandas.tools.merge import concat
3815 if isinstance(other, (list, tuple)):
-> 3816 to_concat = [self] + other
3817 else:
3818 to_concat = [self, other]
TypeError: can only concatenate list (not "tuple") to list
替换以下行:
由
或者干脆
似乎您正试图根据索引(存储在名为
comp_rows
的变量中)筛选出现有的数据帧。您可以使用loc
在不使用循环的情况下执行此操作,如下所示:我们将为所有列获取索引为“a”、“b”和“c”的行:
你可以阅读更多关于它的内容here.
关于你的代码:
一。 不需要遍历列表来查看列表中是否存在项: 使用
in
运算符。例如-所以,代替
做这个
2。 熊猫没有发生。必须将结果存储到另一个变量中。见here。
三。
一次附加一行是一种很慢的方式来完成您想要的任务。 相反,将要添加的每一行保存到列表列表中,对其生成一个数据帧,然后一次性将其附加到目标数据帧。像这样的。。
相关问题 更多 >
编程相关推荐