我想解析文本并将其保存到dataframe。有时信息不存在,比如在二手车里,没有关于座位1的信息,我想在字典里追加一个或任何值。你知道吗
PokerStars Hand #163417399919: Hold'em No Limit (€1/€2 EUR) - 2016/12/23 23:48:52 CET [2016/12/23 17:48:52 ET]
Table 'Dnoces II' 6-max Seat #2 is the button
Seat 1: xxx ($200 in chips)
Seat 2: yyy ($364.58 in chips)
Seat 3: zxc ($200 in chips)
Seat 4: zdf ($235.43 in chips)
Seat 5: zdasdasII ($206.02 in chips)
Seat 6: assfds ($92.53 in chips)PokerStars Hand #162960631727: Hold'em No Limit (€1/€2 EUR) - 2016/12/15 2:10:16 CET [2016/12/14 20:10:16 ET]
Table 'Suleika' 6-max Seat #4 is the button
Seat 2: xxx($137.08 in chips)
Seat 3: yyy ($200 in chips)
Seat 5: xyz($201.20 in chips)PokerStars Hand #163416930846: Hold'em No Limit ($1/$2 USD) - 2016/12/23 23:39:57 CET [2016/12/23 17:39:57 ET]
Table 'Pieksamaki II' 6-max Seat #5 is the button
Seat 1: xxx (€230.90 in chips)
Seat 2: yyy (€256.25 in chips)
Seat 3: zzz (€200 in chips)
Seat 4: ddd (€200 in chips)
Seat 5: ccc (€223.40 in chips)
Seat 6: fff (€77.65 in chips)
file = open(r'example_hands.txt','r')
lines = [i.strip('\n') for i in file]
tab2 = {'Seat1': [],'S1_stack': [], 'Seat2': [], 'S2_stack':[]}
for i in range(len(lines)):
tab2_2 = re.findall('Seat\s1\:\s(\w+)\s\(\$(\d+(\.\d+)?)\s',lines[i])
for t2_2 in tab2_2:
if tab2_2 is None:
tab2['Seat1'].append(None)
tab2['S1_stack'].append(None)
else:
tab2['Seat1'].append(t2_2[0])
tab2['S1_stack'].append(t2_2[1])
tab2_3 = re.findall('Seat\s2\:\s(\w+)\s\(\$(\d+(\.\d+)?)\s',linia[i])
for t2_3 in tab2_3:
tab2['Seat2'].append(t2_3[0])
tab2['S2_stack'].append(t2_3[1])
目前我不能在列表中附加任何值。 有办法解决吗?有可能吗芬德尔先生? 我想要这样的输出:
您可以调整以下原型,它确实从您的文件中提取所有相关信息。你知道吗
作为作业,留给你的唯一一点就是以表格的方式显示它。你知道吗
电流输出:
正则表达式详细信息:
相关问题 更多 >
编程相关推荐