2019-06-26 13:55:29 222浏览
今天千锋扣丁学堂Python培训老师给大家分享一篇关于python读csv文件时指定行为表头或无表头的方法,首先比如pd.read_csv()方法中header参数,默认为0,标签为0(即第1行)的行为表头。若设置为-1,则无表头。下面我们来看一下示例吧。df1=pd.read_csv('target.csv',encoding='utf-8')
df1
import pandas as pd
df2 = pd.read_csv('target.csv',encoding='utf-8',header=1)
df2
df3 = pd.read_csv('target.csv',encoding='utf-8',header=-1)
df3
#! python3
# removeCsvHeader.py - Removes the header from all CSV files in the current
# working directory
import csv, os
os.makedirs('headerRemoved', exist_ok=True)
# Loop through every file in the current working directory.
for csvFilename in os.listdir('.'):
if not csvFilename.endswith('.csv'):
continue # skip non-csv files
【关注微信公众号获取更多学习资料】 【扫码进入Python全栈开发免费公开课】