Python - pandas 数据分析
pandas: powerful Python data analysis toolkit
官方文档: http://pandas.pydata.org/pandas-docs/stable/
1. 导入包pandas
import pandas as pd
2. 获取文件夹下文件名称
import os filenames=[]
path="C:/Users/Forrest/PycharmProjects/test" for file in os.listdir(path): filenames.append(file)
3. 读前几行文件(.csv文件)
# -*- coding: utf-8 -*- ##读前几行文件 f= open("C:/Users/Forrest/PycharmProjects/test/train.csv") for i in range(5): print(f.readline().strip())
4. 读取文件和写文件(.csv文件)
file = pd.read_csv("./非空记录/"+filenames[i],sep='--->',header=None) file.to_csv("./非空all/alldata.csv",header=False,mode='a',index=False) #a追加
5.