<p>不能按<code>$|$</code>拆分,因为它用作正则表达式-请参见<a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.str.split.html" rel="nofollow noreferrer">^{<cd2>}</a>。您需要将其转义到<code>\$\|\$</code>。你知道吗</p>
<p>首先你可以<a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_csv.html" rel="nofollow noreferrer">^{<cd4>}</a>。你知道吗</p>
<p>然后可以使用<a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.stack.html" rel="nofollow noreferrer">^{<cd5>}</a>创建一列进行匹配。然后<a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.concat.html" rel="nofollow noreferrer">^{<cd6>}</a><code>Series</code><code>mouse_lib</code>和<code>human_lib</code>合并成<a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.merge.html" rel="nofollow noreferrer">^{<cd10>}</a>。最后您可以写<code>out</code><a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.to_excel.html" rel="nofollow noreferrer">^{<cd12>}</a>:</p>
<pre><code>#if separator is not ',' use sep=";" for ';' or sep="\s+" for whitespace
library = pd.read_csv("Library.txt")
query = pd.read_csv("Query.txt")
mouse_lib = library['Mouse'].str.split(r"\$\|\$", expand=True).stack()
human_lib= library['Human'].str.split("\$\|\$", expand=True).stack()
df = pd.concat([human_lib, mouse_lib], axis=1, keys=['human','mouse']).reset_index(drop=True, level=1)
</code></pre>
<pre><code>print df
human \
0 LongAUGORFlinc|3P|XLOC_076196|TCONS_00295623:0...
0 linc|3P|XLOC_037932|TCONS_00153577:0.957089|10...
0 linc|3P|XLOC_048756|TCONS_00195334:1.35817|128...
1 EnsASCoding|3P|XLOC_034831|TCONS_00142998:0.39...
1 LongAUGORFlinc|3P|XLOC_033946|TCONS_00137705:0...
1 EnsASCoding|3P|XLOC_000485|TCONS_00003136:0.41...
1 EnsASCoding|3P|XLOC_034831|TCONS_00142998:0.39...
2 linc|3P|XLOC_067039|TCONS_00267121:3.78124|173...
2 linc|3P|XLOC_067039|TCONS_00267116:3.53265|56A...
2 linc|3P|XLOC_067039|TCONS_00267119:0.429515|42...
2 inc|3P|XLOC_067039|TCONS_00267121:3.78124|173A...
mouse
0 linc|3P|XLOC_066319|TCONS_00127223:1.0925|85AA...
0 LongAUGORFEnsASCoding|3P|XLOC_104581|TCONS_002...
0 LongAUGORFEnsASCoding|3P|XLOC_113060|TCONS_002...
1 linc|3P|XLOC_104529|TCONS_00206387:0.585795|11...
1 EnsASCoding|3P|XLOC_082328|TCONS_00160013:0.60...
1 LongAUGORFEnsASCoding|3P|XLOC_097111|TCONS_001...
1 NaN
2 LongAUGORFlinc|3P|XLOC_097853|TCONS_00194306|A...
2 LongAUGORFlinc|3P|XLOC_097853|TCONS_00194302|A...
2 LongAUGORFlinc|3P|XLOC_097853|TCONS_00194307|A...
2 NaN
</code></pre>
<pre><code>out = pd.merge(df, query , left_on=['mouse'], right_on=['XLOC_ID'])
print out
human \
0 linc|3P|XLOC_067039|TCONS_00267119:0.429515|42...
mouse GeneID \
0 LongAUGORFlinc|3P|XLOC_097853|TCONS_00194307|A... A
XLOC_ID
0 LongAUGORFlinc|3P|XLOC_097853|TCONS_00194307|A...
out.to_xls("Matching.xls")
</code></pre>