How do I delete rows not starting with 'x' in Pandas or keep rows starting with 'x'

后端 未结 1 1208
轻奢々
轻奢々 2021-01-18 02:00

I have been at this all morning and have slowly pieced things together. But for the life of me I can not figure out how to use the .str.startswith() function in Pandas.

1条回答
  •  清酒与你
    2021-01-18 02:03

    I am a bit confused by your question. In any case, if you have a DataFrame df with a column 'c', and you would like to remove the items starting with 1, then the safest way would be to use something like:

    df = df[~df['c'].astype(str).str.startswith('1')]
    

    0 讨论(0)
提交回复
热议问题