0

我将以下数据从 excel 表复制到 xml 文件中,我需要从这些数据中创建一个表并将表输出到 Microsoft Outlook,最初我想创建每个列的列表,从中构造 HTMl 代码和输出到excel...如何拆分每一行,因为标题数据可以是任何东西,空格混合等...任何人以前都这样做过,感谢好的建议,等待反馈

CR  FA  CL  TITLE
12345   Dta 656885  Age out SRR values from buffer in Beacon miss scenario
16534   fta 656886  To Record stack Event Logging
76849   cta 654661  To Record HAL and FLM SW Event Logging
45678   CT  656928  CR1234: BT doesn’t work that Riva neither sends HCI Evt for HID ACL data nor response to CI after entering into real sniffer rat mode.
4

4 回答 4

2

用于csv.DictReader将数据放入字典:

>>> import csv
>>> with open('t.txt') as f:
...    reader = csv.DictReader(f,dialect='excel-tab')
...    rows = list(reader)
... 
>>> rows[0]
{'TITLE': 'Age out SRR values from buffer in Beacon miss scenario',
 'CR': '12345', 'CL': '656885', 'FA': 'Dta'}
于 2012-11-07T19:10:31.863 回答
1

如果只有最后一列更复杂,您可以使用 re.split ->

import re
input="""CR FA  CL  TITLE
12345   Dta 656885  Age out SRR values from buffer in Beacon miss scenario
16534   fta 656886  To Record stack Event Logging
76849   cta 654661  To Record HAL and FLM SW Event Logging
45678   CT  656928  CR1234: BT doesn’t work that Riva neither sends HCI Evt for HID ACL data nor response to CI after entering into real sniffer rat mode."""

[re.split(r'\W+',i,3) for i in input.splitlines()]
于 2012-11-07T19:32:55.357 回答
0

确保为您的 csv 使用正确的分隔符 ...(请参阅附件调整后的数据文件,使用制表符分隔)https://dl.dropbox.com/u/18004504/data.csv

import pandas as pd
df=pd.DataFrame.from_csv("data.csv",sep="\t",parse_dates=False)


print df
for row in df.iterrows(): 
    print row
    print "-------"
于 2012-11-07T19:58:52.123 回答
0

如果您可以找到每行内容的模式,那么您可以更轻松地解析该行。每行1记录吗?如果是这样,请参见下文。

for line in open('myfile','r').readlines():
    # Do whatever you need to the line variable.
于 2012-11-07T18:59:42.803 回答