zoukankan      html  css  js  c++  java
  • pandas-文件加载

    读取csv

    使用 read_csv 读取

    sms = pd.read_csv('./data/SMSSpamCollection', sep=' ',header=None)

    sep: 分隔符 header: 不要表头

    读取txt

    pd.read_csv('./type-.txt', sep='-', header=None)

    使用 read_table读取

    pd.read_table('./data/SMSSpamCollection', header=None)

     

    读取excel表格

    pd.read_excel('./read_xlsx.xlsx', sheet_name=2)

     

    读取sqlite文件

    conn = sqlite3.connect('./data.sqlite')

    weather_2017 = pd.read_sql('select * from weather_2017 limit 30', conn, index_col='index')

    - 设置行索引index_col

     

    写入文件

    weather_2017.to_csv('./weather_2017.csv')

    weather_2017.to_json('./weather_2017.json')

    weather_2017.to_html('./weather_2017.html')

    weather_2017.to_sql('weather_2019', conn, if_exists='append')

     

    从mysql读取

    import pymysql

    conn = pymysql.connect(host='127.0.0.1', port=3306, user='root', password='root', database='maoyan', charset='utf8')

    goods_data = pd.read_sql('select * from goods limit 20',conn)

    写入mysql

    from sqlalchemy import create_engine

    engine = create_engine('mysql+mysqldb://root:450502@localhost:3306/?charset=utf8')

    goods.to_sql('goods', engine)

     

    根据url获取网络上的数据

    pd.read_csv('https://raw.githubusercontent.com/datasets/investor-flow-of-funds-us/master/data/weekly.csv')

  • 相关阅读:
    路由器的配置及使用
    OSI与TCP/IP网络模型
    IP地址
    C++中的虚函数
    虚基类
    【idea】jrebel
    JSON(来自ww3school)
    get与post
    Ajax(来自w3school)
    EasyUI——combotree
  • 原文地址:https://www.cnblogs.com/Deaseyy/p/11921642.html
Copyright © 2011-2022 走看看