我有如下的 CSV 数据,
Schedule Start Time Schedule End Time Interval System IP - Login User
3-30-2018 1:22 03-30-2018 02:21 00 hour 5 minute 10.1.1.3
Grep Command Result
Schedule Time ECM MAC ImageName
03-30-2018 01:22 B4:A5:EF:F2:27 UNAVAILABLE
03-30-2018 01:27 B4:A5:EF:F2:27 UNAVAILABLE
03-30-2018 01:32 B4:A5:EF:F2:27 UNAVAILABLE
03-30-2018 01:37 B4:A5:EF:F2:27 UNAVAILABLE
03-30-2018 01:42 B4:A5:EF:F2:27 UNAVAILABLE
03-30-2018 01:47 B4:A5:EF:F2:27 UNAVAILABLE
03-30-2018 01:52 B4:A5:EF:F2:27 UNAVAILABLE
03-30-2018 01:57 B4:A5:EF:F2:27 UNAVAILABLE
03-30-2018 02:02 B4:A5:EF:F2:27 UNAVAILABLE
03-30-2018 02:07 B4:A5:EF:F2:27 UNAVAILABLE
03-30-2018 02:12 B4:A5:EF:F2:27 UNAVAILABLE
03-30-2018 02:17 B4:A5:EF:F2:27 UNAVAILABLE
我想解析Schedule Time,ECM MAC,ImageName
这些列,我怎么能在 python 中做到这一点,我试过了
file1='testcsv.csv'
red=pd.read_csv(file1,skipinitialspace=True,usecols=['Schedule Time','ECM MAC','ImageName'])
print red
但我得到,
File "/Library/Python/2.7/site-packages/pandas/io/parsers.py", line 1740, in __init__
raise ValueError("Usecols do not match names")
任何人都可以建议最好的解决方案吗?谢谢
我不确定您是否可以使用 read_csv 轻松解析。但是您可以跳过第一行并到达信息所在的位置:
pd.read_csv('schedule.csv',skiprows=8, sep=' ',
index_col=False, skipinitialspace=True,
names=['Schedule Time', 'ECM', 'MAC', 'ImageName'])`
这是对列名称使用“名称”。它将分隔符设置为 ' ',因为默认值为 ',' 并且正在跳过信息的第一行。index_col=False 强制 read_csv 不使用第一列作为索引列。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句