zoukankan      html  css  js  c++  java
  • 写入/读取csv文件(使用Python的csv包)

    写入:

    with open(qa_csv_path, "w") as csv_file:
    # 设定写入模式
    csv_write = csv.writer(csv_file, dialect='excel')
    for l in write_list:
    csv_write.writerow(l)

    读取:
    with open(data_dir, "r") as f:
    csv_file = csv.reader(f)
    for line in csv_file

        print(line)
     

    pd.read_csv()方法中header参数,默认为0,标签为0(即第1行)的行为表头。若设置为-1,则无表头。示例如下:

    (1)不设置header参数(默认)时:

    df1 = pd.read_csv('target.csv',encoding='utf-8')
    df1
    

    (2)header=1时:

    import pandas as pd
    df2 = pd.read_csv('target.csv',encoding='utf-8',header=1)
    df2
      

    (3)header=-1时(可用于读取无表头CSV文件):

    df3 = pd.read_csv('target.csv',encoding='utf-8',header=-1)
    df3
     
    
    
    
     
  • 相关阅读:
    next_permutation( ) 和prev_permutation( ) 全排列函数
    F
    STL入门
    H
    C
    提交按钮组件
    JScorllPane面板(带滚轮的JPane)
    JPanel画板
    网络布局管理器
    边界布局管理器
  • 原文地址:https://www.cnblogs.com/gagaein/p/14801750.html
Copyright © 2011-2022 走看看