Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 熊猫:使用'删除行;tmp&x27;在他们里面_Python_Pandas_Dataframe_Row - Fatal编程技术网

Python 熊猫:使用'删除行;tmp&x27;在他们里面

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

我在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
我希望运行一个命令来完全删除所有以“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”。