<pre><code>import pandas as pd
from collections import defaultdict
from ast import literal_eval
pairs = defaultdict (int,
{"['por', 'rus']": 80,
"['nld', 'slv']": 4,
"['jpn', 'pol']": 48,
"['ces', 'epo']": 4,
"['oci', 'ron']": 4,
"['lit', 'mkd']": 2,
"['deu', 'ewe']": 2,
"['cat', 'ron']": 4,
"['ces', 'ita']": 18,
"['est', 'fra']": 14,
"['hin', 'mal']": 4})
df = pd.DataFrame(list(pairs.iteritems()), columns = ['column1','column2'])
print df
column1 column2
0 ['por', 'rus'] 80
1 ['est', 'fra'] 14
2 ['nld', 'slv'] 4
3 ['jpn', 'pol'] 48
4 ['ces', 'epo'] 4
5 ['hin', 'mal'] 4
6 ['oci', 'ron'] 4
7 ['lit', 'mkd'] 2
8 ['deu', 'ewe'] 2
9 ['cat', 'ron'] 4
10 ['ces', 'ita'] 18
print type(df.at[0,'column1'])
<type 'str'>
</code></pre>
<p>您可以首先通过<a href="https://docs.python.org/2/library/ast.html" rel="nofollow">^{<cd3>}</a>将<code>string list</code>更改为<code>list</code>,然后创建<code>DataFrame</code><a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.from_records.html" rel="nofollow">^{<cd5>}</a>和最后一个<a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.concat.html" rel="nofollow">^{<cd6>}</a><code>column2</code>:</p>
<pre><code>#change type string to list
df['column1'] = df['column1'].apply(literal_eval)
print df
column1 column2
0 [por, rus] 80
1 [est, fra] 14
2 [nld, slv] 4
3 [jpn, pol] 48
4 [ces, epo] 4
5 [hin, mal] 4
6 [oci, ron] 4
7 [lit, mkd] 2
8 [deu, ewe] 2
9 [cat, ron] 4
10 [ces, ita] 18
print type(df.at[0,'column1'])
<type 'list'>
</code></pre>
<pre><code>df1 = pd.DataFrame.from_records([x for x in df['column1']], columns=['a','b'])
print df1
a b
0 por rus
1 est fra
2 nld slv
3 jpn pol
4 ces epo
5 hin mal
6 oci ron
7 lit mkd
8 deu ewe
9 cat ron
10 ces ita
print pd.concat([df1, df['column2']], axis=1)
a b column2
0 por rus 80
1 est fra 14
2 nld slv 4
3 jpn pol 48
4 ces epo 4
5 hin mal 4
6 oci ron 4
7 lit mkd 2
8 deu ewe 2
9 cat ron 4
10 ces ita 18
</code></pre>
<p>或者使用<a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.str.strip.html" rel="nofollow">^{<cd8>}</a>和<a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.str.replace.html" rel="nofollow">^{<cd9>}</a>清洁<code>column1</code>,然后通过<a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.str.split.html" rel="nofollow">^{<cd12>}</a>和<a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.concat.html" rel="nofollow">^{<cd6>}</a><code>column2</code>创建新的<code>DataFrame</code>:</p>
<pre><code>df['column1'] = df['column1'].str.strip('[]').str.replace("'","")
print df
column1 column2
0 por, rus 80
1 est, fra 14
2 nld, slv 4
3 jpn, pol 48
4 ces, epo 4
5 hin, mal 4
6 oci, ron 4
7 lit, mkd 2
8 deu, ewe 2
9 cat, ron 4
10 ces, ita 18
</code></pre>
<pre><code>df1 = df['column1'].str.split(",", expand=True)
df1.columns = ['a','b']
print df1
a b
0 por rus
1 est fra
2 nld slv
3 jpn pol
4 ces epo
5 hin mal
6 oci ron
7 lit mkd
8 deu ewe
9 cat ron
10 ces ita
print pd.concat([df1, df['column2']], axis=1)
a b column2
0 por rus 80
1 est fra 14
2 nld slv 4
3 jpn pol 48
4 ces epo 4
5 hin mal 4
6 oci ron 4
7 lit mkd 2
8 deu ewe 2
9 cat ron 4
10 ces ita 18
</code></pre>