Python 熊猫:使用'删除行;tmp&x27;在他们里面
我在Python中有一个pandas数据框,该数据框如下所示:Python 熊猫:使用'删除行;tmp&x27;在他们里面,python,pandas,dataframe,row,Python,Pandas,Dataframe,Row,我在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
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
我希望运行一个命令来完全删除所有以“tmp”开头的table_name
行,因此对于我的示例,结果是:
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
表_名称中没有一个包含“temp”。你是说“tmp”吗?@EricShain是的,先生。谢谢,已编辑。您的结果表中还包含一行,其中包含“tmp”。