Skip to main content
 首页 » 编程设计

python之删除 pandas 数据框中以注释字符开头的项目

2024年12月31日8xiaohuochai

<分区>

我想删除 pandas 数据框中以注释字符开头的所有行。例如:

>>> COMMENT_CHAR = '#' 
>>> df 
    first_name    last_name 
0   #fill in here fill in here 
1   tom           jones 
 
>>> df.remove(df.columns[0], startswith=COMMENT_CHAR) # in pseudocode 
>>> df 
    first_name    last_name 
0   tom           jones 

这实际上是如何完成的?