,可以使用正则表达式和pandas的str.contains()方法来实现。
首先,导入pandas库并读取数据到Dataframe中:
import pandas as pd
# 读取数据到Dataframe
df = pd.DataFrame({'text': ['http://example.com', 'https://example.com', 'www.example.com', 'http://example.org']})
接下来,使用正则表达式和str.contains()方法来筛选出以“http”开头的单词所在的行:
# 使用正则表达式筛选出以"http"开头的单词所在的行
mask = df['text'].str.contains(r'^http')
# 删除符合条件的行
df = df[~mask]
最后,打印删除以“http”开头的单词后的Dataframe:
print(df)
输出结果为:
text
1 https://example.com
2 www.example.com
在这个例子中,我们使用了正则表达式的"^http"模式来匹配以"http"开头的单词。然后,使用~操作符来取反,得到不符合条件的行。最后,将不符合条件的行重新赋值给原始的Dataframe,即删除了以“http”开头的单词所在的行。
推荐的腾讯云相关产品:腾讯云云服务器(CVM)和腾讯云云数据库MySQL。
领取专属 10元无门槛券
手把手带您无忧上云