目前该计划如下:
A1
Salary
Year
2007 2750
2008 2850
2009 2700
2010 2900
2011 3000
2012 3050
2013 3050
2014 3200
2015 3300
2016 3300
乙1
GDP for Year
Year
2007 271249.8
2008 271980.4
2009 279858.0
2010 322361.1
2011 346649.0
2012 361365.9
2013 378531.6
2014 390447.7
2015 408096.6
2016 410271.9
当我合并它时,它显示:
pd.concat([a1, b1], axis=1, ignore_index=False)
Salary GDP for Year
Year
2007 2750.0 NaN
2008 2850.0 NaN
2009 2700.0 NaN
2010 2900.0 NaN
2011 3000.0 NaN
2012 3050.0 NaN
2013 3050.0 NaN
2014 3200.0 NaN
2015 3300.0 NaN
2016 3300.0 NaN
2007 NaN 271249.8
2008 NaN 271980.4
2009 NaN 279858.0
2010 NaN 322361.1
2011 NaN 346649.0
2012 NaN 361365.9
2013 NaN 378531.6
我希望将它打印为:
Salary GDP For Year
Year
2007 2750 . 271249.8
2008 2850 . 271980.4
2009 2700 . 279858.0
2010 2900 . 322361.1
2011 3000 . 346649.0
2012 3050 . 361365.9
2013 3050 . 378531.6
2014 3200 . 390447.7
2015 3300 . 408096.6
2016 3300 . 410271.9
之后,我想绘制一个图表,并创建一个比较,看看两条线在一个图形中如何相互比较。
到目前为止,我已经尝试过,合并,加入,连接但没有任何内容。
其中一个dataframe的索引是string类型,而另一个是整数
rename
a1.rename(int, inplace=True)
b1.rename(int, inplace=True)
pd.concat([a1, b1], axis=1)
Salary GDP for Year
Year
2007 2750 271249.8
2008 2850 271980.4
2009 2700 279858.0
2010 2900 322361.1
2011 3000 346649.0
2012 3050 361365.9
2013 3050 378531.6
2014 3200 390447.7
2015 3300 408096.6
2016 3300 410271.9
index
a1.index = a1.index.astype(int)
b1.index = b1.index.astype(int)
pd.concat([a1, b1], axis=1)
尝试:
pd.concat([a1, b1], axis='col', ignore_index=False)