How to delete a column from a data frame with pandas?

前端 未结 3 1989
梦如初夏
梦如初夏 2020-12-24 11:00

I read my data

import pandas as pd
df = pd.read_csv(\'/path/file.tsv\', header=0, delimiter=\'\\t\')
print df

and get:

             


        
3条回答
  •  清酒与你
    2020-12-24 11:54

    df.drop(colname, axis=1) (or del df[colname]) is the correct method to use to delete a column.

    If a ValueError is raised, it means the column name is not exactly what you think it is.

    Check df.columns to see what Pandas thinks are the names of the columns.

提交回复
热议问题