我有一個CSV文件中像這樣的:分離列用「」和去掉一個新列
"NoDemande;"NoUsager";"Sens";"IdVehicule";"NoConducteur";"NoAdresse";"Fait";"aPaye";"MethodePaiement";"ArgentPercu";"HeurePrevue";"HeureDebutTrajet";"HeureArriveeSurSite";"HeureEffective"
0003;"2021";"+";"157Véh";"0002";"5712";"1";"";"";"";"07/07/2015 06:30:04";"07/07/2015 06:15:48";"07/07/2015 06:32:14";"07/07/2015 06:32:23"
0265;"0496";"+";"161Véh";"0035";"04075";"1";"";"";"";"07/07/2015 06:35:04";"07/07/2015 05:09:55";"07/07/2015 06:36:18";"07/07/2015 06:36:27"
0004;"2208";"+";"157Véh";"0002";"5713";"1";"";"";"";"07/07/2015 06:45:04";"07/07/2015 06:32:23";"07/07/2015 06:40:05";"07/07/2015 06:40:10"
我想要做什麼:
- 拆分某些列,使得'日期'和'時間'分爲兩列。
- 只保存「日期」的一列並刪除其中一列。
而且我想是這樣的:
#coding=latin-1
import pandas as pd
import glob
pd.set_option('expand_frame_repr', False)
path = r'D:\Python27\mypfe\data_test'
allFiles = glob.glob(path + "/*.csv")
frame = pd.DataFrame()
list_ = []
for file_ in allFiles:
df = pd.read_csv(file_,index_col=None,header=0,sep=';')
s1 = df['HeurePrevue'].apply(lambda x: x.split(' '))
df['Date'] = s1.apply(lambda x: x[0])
df['HeurePrevue'] = s1.apply(lambda x: x[1])
frame = pd.concat(list_)
print frame
它與一列,但是當我想要做同樣的第二它不再起作用。我應該怎麼做才能使其與我的所有專欄一起工作,同時保留其他專欄的內容?
我沒有看到你試圖分裂隨後僅列第 – EdChum
我只成功在分裂前... – ch36r5s