pandas记录之端午节的淘宝粽子交易分析

    技术2022-07-11  79

    1、列名中有空格

    df.columns Index(['标题', ' 价格', '付款人数', '店铺', '发货地址 '], dtype='object')

    去除空格 strip():删除字符串前后的空白;lstrip():删除字符串前面(左边)的空白;rstrip():删除字符串后面(右边)的空白。这三个方法只是返回空白被删除之后的副本,没改变字符串本身

    [name.strip() for name in df.columns] ['标题', '价格', '付款人数', '店铺', '发货地址'] df.columns=[name.strip() for name in df.columns]

    2、价格为string,必有非数值数据,付款人数71行缺失数据,发货地址3行缺失数据

    df.info() <class 'pandas.core.frame.DataFrame'> RangeIndex: 4403 entries, 0 to 4402 Data columns (total 5 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 标题 4403 non-null string 1 价格 4403 non-null string 2 付款人数 4332 non-null string 3 店铺 4403 non-null string 4 发货地址 4400 non-null string dtypes: string(5) memory usage: 172.1 KB df.isna().sum() Out[30]:标题 0 价格 0 付款人数 71 店铺 0 发货地址 3 dtype: int64 df[df['发货地址'].isna().T] 未完待续,持续更新
    Processed: 0.024, SQL: 9