简体   繁体   中英

python panda :how to delete row from csv file

i want to delete empty row(last row) from csv file

I searched a lot about the solution but didn't found

熊猫

Try this

import pandas as pd
import numpy as np

df = pd.DataFrame({'A':[1,2,3,''], 'B': [4,5,'', 6]})
df = df.replace('', np.nan)
df = df.dropna()
print(df)

Output:

     A    B
0  1.0  4.0
1  2.0  5.0

You can delete column using del

del df['column_name']

This works I think -

df = df.dropna(axis=0, subset=['Column name'])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM