zoukankan      html  css  js  c++  java
  • pandas之数据读取

    '''
        数据的读取
    '''
    import pandas as pd
    import warnings
    
    warnings.filterwarnings('ignore')
    
    # 读取文本文件
    users = pd.read_table('./users.dat', header=None, names=['UserID', 'Gender', 'Age', 'Occupation', 'Zip-code'], sep='::',
                          engine='python')
    print(users.head())
    
    # 读取csv文件
    csv = pd.read_csv('./iris.csv', header=None, names=['width', 'height', 'category'], sep=',', engine='python')
    print(csv.head())
    csv.iloc[0, 2] = 1
    csv.to_csv('./iris1.csv')
    
    # 读取excel文件
    excel = pd.read_excel('./data.xlsx')
    print(excel)
    
    
    输出结果:
    
       UserID Gender  Age  Occupation Zip-code
    0       1      F    1          10    48067
    1       2      M   56          16    70072
    2       3      M   25          15    55117
    3       4      M   45           7    02460
    4       5      M   25          20    55455
       width  height  category
    0    1.4     0.2         0
    1    1.4     0.2         0
    2    1.3     0.2         0
    3    1.5     0.2         0
    4    1.4     0.2         0
       age  height gender
    0   21     165      M
    1   22     145      M
    2   23     164      M
    3   24     165      M
    4   25     166      F
    5   26     167      F
  • 相关阅读:
    解析XML
    事务
    js小工具
    plsql用过的流程语句
    查询语句
    存储过程
    用过的CRT命令
    mysql常用命令
    Spirng MVC demo 完整示例01 环境搭建
    jmeter多个http请求串联
  • 原文地址:https://www.cnblogs.com/yuxiangyang/p/11266228.html
Copyright © 2011-2022 走看看