美文网首页
pandas操作手册

pandas操作手册

作者: 陆寒晨 | 来源:发表于2019-12-11 11:01 被阅读0次

1、删除一列:

    Del df[column] -> df的列直接被删除;

    Df.drop(col,axis=1) -> 删除一列,不改变原df,重新赋值一个新的df

    Df.drop(col,axis=1,inplace=True) -> 直接改变原df的值   

2、查看df每列数据类型:

    Df[col].dtype==‘object’ == True

    Df[col].dtype==‘int’ == True

    Df[col].dtype==‘float’ == True

3、强制修改df某列类型:

    Df[col]=df[col].astype(float) -> 将col列改为float类型

4、DataFrame中方差为0的列:

    Series=df.var() ## 获取方差series

    Lst_col=Series[Series.values == 0].index.tolist()

5、打印异常

try:

    Execute()

Exception as err:

    Print(err)

 

相关文章

网友评论

      本文标题:pandas操作手册

      本文链接:https://www.haomeiwen.com/subject/qcrogctx.html