• object数据类型


    1 object数据类型是dataframe中特殊的数据类型,当某一列出现数字、字符串、特殊字符和时间格式两种及以上时,就会出现object类型,即便把不同类型的拆分开,仍然是object类型.

    如下replace()函数改变数据类型后,用astype()函数再转化一次才能将object格式转化,但有的时候不用.

    print(train.info())
    train['repay_date'] = train['repay_date'].replace("\N",'2020-01-01')
    train['repay_date'] = pd.to_datetime(train['repay_date'])
    train['repay_amt'] = train['repay_amt'].replace("\N",0)
    train['repay_amt'] = train['repay_amt'].astype(float)
    print(train.info())
    # <class 'pandas.core.frame.DataFrame'>
    # RangeIndex: 1000000 entries, 0 to 999999
    # Data columns (total 7 columns):
    # user_id       1000000 non-null int64
    # listing_id    1000000 non-null int64
    # due_date      1000000 non-null datetime64[ns]
    # due_amt       1000000 non-null float64
    # repay_date    1000000 non-null object
    # repay_amt     1000000 non-null object
    # order_id      1000000 non-null int64
    # dtypes: datetime64[ns](1), float64(1), int64(3), object(2)
    # memory usage: 53.4+ MB
    # None
    # <class 'pandas.core.frame.DataFrame'>
    # RangeIndex: 1000000 entries, 0 to 999999
    # Data columns (total 7 columns):
    # user_id       1000000 non-null int64
    # listing_id    1000000 non-null int64
    # due_date      1000000 non-null datetime64[ns]
    # due_amt       1000000 non-null float64
    # repay_date    1000000 non-null datetime64[ns]
    # repay_amt     1000000 non-null float64
    # order_id      1000000 non-null int64
    # dtypes: datetime64[ns](2), float64(2), int64(3)
    # memory usage: 53.4 MB
    # None

     

  • 相关阅读:
    WPF Video Tutorials
    英语词汇看病
    回车键的含义
    勘误《新概念》IV
    2010年春季C语言程序设计答疑时间地点安排
    勘误《新概念》III
    A potentially dangerous Request.Form value was detected from the client
    推荐WPF的好书(图书)
    *英语词汇交通
    英语词汇房地产
  • 原文地址:https://www.cnblogs.com/xxswkl/p/11002954.html
Copyright © 2020-2023  润新知