pandas:删除其中包含 'tmp' 的行
pandas: remove rows with 'tmp' in them
我在 Python 中有一个 pandas 数据框,数据框如下所示:
id count table_size table_name
1 835 0.52 some_table
2 543 1.02 another_table
3 727 0.85 tmp_test_table
4 834 1.46 empty_table
5 552 0.99 tmp_my_table
我希望 运行 一个命令完全删除所有 table_name
以“tmp”开头的行,因此对于我的示例,结果将是:
id count table_size table_name
1 835 0.52 some_table
2 543 1.02 another_table
5 552 0.99 tmp_my_table
我不在乎id被弄乱了
使用str.startswith过滤掉
df[~df.table_name.str.startswith('tmp')]
id count table_size table_name
0 1 835 0.52 some_table
1 2 543 1.02 another_table
3 4 834 1.46 empty_table
我在 Python 中有一个 pandas 数据框,数据框如下所示:
id count table_size table_name
1 835 0.52 some_table
2 543 1.02 another_table
3 727 0.85 tmp_test_table
4 834 1.46 empty_table
5 552 0.99 tmp_my_table
我希望 运行 一个命令完全删除所有 table_name
以“tmp”开头的行,因此对于我的示例,结果将是:
id count table_size table_name
1 835 0.52 some_table
2 543 1.02 another_table
5 552 0.99 tmp_my_table
我不在乎id被弄乱了
使用str.startswith过滤掉
df[~df.table_name.str.startswith('tmp')]
id count table_size table_name
0 1 835 0.52 some_table
1 2 543 1.02 another_table
3 4 834 1.46 empty_table