<p>我也有同样的问题。从欧盟统计局下载的数据,其结构相同。我尝试了@EdChum的解决方案,但我不能一蹴而就,所以我需要进一步的步骤:</p>
<pre><code>vc.head() # The original DataFrame
Out[150]:
expend,unit,geo\time 2015 2014 2013 2012 2011 2010 2009 \
0 INV,MIO_EUR,AT 109 106.0 86.0 155.0 124.0 130.0 140.0
1 INV,MIO_EUR,BE 722 664.0 925.0 522.0 590.0 476.0 1018.0
2 INV,MIO_EUR,BG 16 1.0 2.0 65.0 11.0 5.0 6.0
3 INV,MIO_EUR,CH 640 1237.0 609.0 662.0 640.0 1555.0 718.0
4 INV,MIO_EUR,CZ 13 14.0 24.0 17.0 193.0 37.0 61.0
cols = 'expend,unit,geo\time'.split(',') # Getting the columnns
clean = vc.iloc[:,0].str.split(',').apply(pd.Series) # Creating a clean version
clean = clean.rename(columns = lambda x: cols[x]) # Adding the column names to the clean version
vc = pd.concat([clean, vc.iloc[:,1:]], axis = 1) # Concatenating the two tables
vc.head()
Out[155]:
expend unit geo\time 2015 2014 2013 2012 2011 2010 2009 \
0 INV MIO_EUR AT 109 106.0 86.0 155.0 124.0 130.0 140.0
1 INV MIO_EUR BE 722 664.0 925.0 522.0 590.0 476.0 1018.0
2 INV MIO_EUR BG 16 1.0 2.0 65.0 11.0 5.0 6.0
3 INV MIO_EUR CH 640 1237.0 609.0 662.0 640.0 1555.0 718.0
4 INV MIO_EUR CZ 13 14.0 24.0 17.0 193.0 37.0 61.0
</code></pre>