【发布时间】:2017-02-11 09:16:39
【问题描述】:
my dataframe df:
index url
1 [{'url': 'http://bhandarkarscollegekdp.org/'}]
2 [{'url': 'http://cateringinyourhome.com/'}]
3 NaN
4 [{'url': 'http://muddyjunction.com/'}]
5 [{'url': 'http://ecskouhou.jp/'}]
6 [{'url': 'http://andersrice.com/'}]
7 [{'url': 'http://durager.cz/'}, {'url': 'http:andersrice.com'}]
8 [{'url': 'http://milenijum-osiguranje.rs/'}]
9 [{'url': 'http://form-kind.org/'}, {'url': 'https://osiguranje'},{'url': 'http://beseka.com.tr'}]
如果url列的行列表中的最后一项包含'https',我想选择行,同时跳过缺失值。
我当前的脚本
df[df['url'].str[-1].str.contains('https',na=False)]
为所有行返回 False 值,而其中一些实际上包含 https。
有人可以帮忙吗?
【问题讨论】:
-
print (type(df.ix[1,'url']))是什么? -
@jezrael 它是列表
-
因为你的 dtype 是你必须使用的列表
apply:df['url'].apply(lambda x: 'https' in x[-1]) -
@EdChum 我试过了。它死了也不起作用。 TypeError: 'float' 对象不可下标
-
试试
df['url'].dropna().apply(lambda x: 'https' in x[-1]['url'])
标签: python loops pandas contain