Remove a single row from a csv without copying files

后端 未结 7 2255
青春惊慌失措
青春惊慌失措 2020-12-06 00:07

There are multiple SO questions addressing some form of this topic, but they all seem terribly inefficient for removing only a single row from a csv file (usually they invol

7条回答
  •  执念已碎
    2020-12-06 00:51

    You can do it using Pandas. If your data is saved under data.csv, the following should help:

    import pandas as pd
    
    df = pd.read_csv('data.csv')
    df = df[df.fname != 'Sarah' ]
    df.to_csv('data.csv', index=False)
    

提交回复
热议问题