我想在下面在Phyton中使用的代码中添加一行,以便删除第一列中名为“仇恨”的所有行,即“生物”:
import pandas as pd
from datetime import datetime
INPUT_FILE = 'Sample spreadsheet.xlsx'
OUTPUT_FILE = 'Output.xlsx'
df = pd.read_excel(INPUT_FILE)
df.dropna(subset=['Location', 'Full name'], inplace=True)
df = df[(df['Followers'] > 200) & (df['Friends'] > 200) & (df['Last tweet'] > '2011-04-12') & (df['Created'] < '2018-12-31')]
with pd.ExcelWriter(OUTPUT_FILE) as writer:
df.to_excel(writer)
答案 0 :(得分:2)
我会在调用包含之前添加小写字母!这意味着仇恨,仇恨和仇恨会被抓住:
UPDATE tablename
SET columname = TRIM(TRAILING '\n' FROM REGEXP_SUBSTR(columname,".*\n"))
WHERE TRIM(TRAILING '\n' FROM REGEXP_SUBSTR(columname,".*\n")) =
TRIM(LEADING '\n' FROM REGEXP_SUBSTR(columname,"\n.*"))
;
熊猫文档:https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.str.contains.html
结果:
答案 1 :(得分:1)
如果要删除包含单词“ hate”的字符串:
df = df[~df["Bio"].str.contains("hate")]
答案 2 :(得分:0)
使用此行
df = df[df['Bio'] != 'hate']
如果该列可以包含多个值,则可以使用
df = df[~df["Bio"].str.lower().contains("hate")]