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.