# 1108plotly01 **Repository Path**: NFUNM089/1108plotly01 ## Basic Information - **Project Name**: 1108plotly01 - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2019-11-08 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README Untitled2
In [22]:
import plotly as py
py.offline.init_notebook_mode()
In [47]:
import pandas as pd
df = pd.read_csv("jiuye.csv",encoding='gbk')
df
Out[47]:
指标 2018 2017 2016 2015 2014 2013 2012 2011 2010 ... 2008 2007 2006 2005 2004 2003 2002 2001 2000 1999
0 就业人员(万人) 77586 77640 77603 77451 77253 76977 76704 76420 76105 ... 75564 75321 74978 74647 74264 73736 73280 72797 72085 71394
1 城镇就业人员(万人) 43419 42462 41428 40410 39310 38240 37102 35914 34687 ... 32103 30953 29630 28389 27293 26230 25159 24123 23151 22412
2 乡村就业人员(万人) 34167 35178 36175 37041 37943 38737 39602 40506 41418 ... 43461 44368 45348 46258 46971 47506 48121 48674 48934 48982

3 rows × 21 columns

In [48]:
df.index
Out[48]:
RangeIndex(start=0, stop=3, step=1)
In [49]:
df.columns
Out[49]:
Index(['指标', '2018', '2017', '2016', '2015', '2014', '2013', '2012', '2011',
       '2010', '2009', '2008', '2007', '2006', '2005', '2004', '2003', '2002',
       '2001', '2000', '1999'],
      dtype='object')
In [50]:
dfc=df.set_index("指标")
dfc.head()
Out[50]:
2018 2017 2016 2015 2014 2013 2012 2011 2010 2009 2008 2007 2006 2005 2004 2003 2002 2001 2000 1999
指标
就业人员(万人) 77586 77640 77603 77451 77253 76977 76704 76420 76105 75828 75564 75321 74978 74647 74264 73736 73280 72797 72085 71394
城镇就业人员(万人) 43419 42462 41428 40410 39310 38240 37102 35914 34687 33322 32103 30953 29630 28389 27293 26230 25159 24123 23151 22412
乡村就业人员(万人) 34167 35178 36175 37041 37943 38737 39602 40506 41418 42506 43461 44368 45348 46258 46971 47506 48121 48674 48934 48982
In [51]:
dfc.index
Out[51]:
Index(['就业人员(万人)', '城镇就业人员(万人)', '乡村就业人员(万人)'], dtype='object', name='指标')
In [52]:
dfc.columns
Out[52]:
Index(['2018', '2017', '2016', '2015', '2014', '2013', '2012', '2011', '2010',
       '2009', '2008', '2007', '2006', '2005', '2004', '2003', '2002', '2001',
       '2000', '1999'],
      dtype='object')
In [53]:
[int(x) for x in dfc.columns]
Out[53]:
[2018,
 2017,
 2016,
 2015,
 2014,
 2013,
 2012,
 2011,
 2010,
 2009,
 2008,
 2007,
 2006,
 2005,
 2004,
 2003,
 2002,
 2001,
 2000,
 1999]
In [54]:
dfc.loc["城镇就业人员(万人)",:]
Out[54]:
2018    43419
2017    42462
2016    41428
2015    40410
2014    39310
2013    38240
2012    37102
2011    35914
2010    34687
2009    33322
2008    32103
2007    30953
2006    29630
2005    28389
2004    27293
2003    26230
2002    25159
2001    24123
2000    23151
1999    22412
Name: 城镇就业人员(万人), dtype: int64
In [55]:
dfc.loc["城镇就业人员(万人)",:].name
Out[55]:
'城镇就业人员(万人)'
In [56]:
dfc.loc["城镇就业人员(万人)",:].values
Out[56]:
array([43419, 42462, 41428, 40410, 39310, 38240, 37102, 35914, 34687,
       33322, 32103, 30953, 29630, 28389, 27293, 26230, 25159, 24123,
       23151, 22412], dtype=int64)
In [57]:
dfc.loc["城镇就业人员(万人)",:].index
Out[57]:
Index(['2018', '2017', '2016', '2015', '2014', '2013', '2012', '2011', '2010',
       '2009', '2008', '2007', '2006', '2005', '2004', '2003', '2002', '2001',
       '2000', '1999'],
      dtype='object')
In [58]:
import plotly as py
from plotly.graph_objs import Scatter, Layout, Data

trace0 = Scatter(
    x=[int(x) for x in dfc.columns],
    y=dfc.loc["城镇就业人员(万人)",:].values
)
In [59]:
py.offline.plot([trace0],filename = 'output_US.html')
Out[59]:
'output_US.html'
In [60]:
dfc.loc["乡村就业人员(万人)",:]
Out[60]:
2018    34167
2017    35178
2016    36175
2015    37041
2014    37943
2013    38737
2012    39602
2011    40506
2010    41418
2009    42506
2008    43461
2007    44368
2006    45348
2005    46258
2004    46971
2003    47506
2002    48121
2001    48674
2000    48934
1999    48982
Name: 乡村就业人员(万人), dtype: int64
In [61]:
dfc.loc["乡村就业人员(万人)",:].name
Out[61]:
'乡村就业人员(万人)'
In [62]:
dfc.loc["乡村就业人员(万人)",:].values
Out[62]:
array([34167, 35178, 36175, 37041, 37943, 38737, 39602, 40506, 41418,
       42506, 43461, 44368, 45348, 46258, 46971, 47506, 48121, 48674,
       48934, 48982], dtype=int64)
In [63]:
dfc.loc["乡村就业人员(万人)",:].index
Out[63]:
Index(['2018', '2017', '2016', '2015', '2014', '2013', '2012', '2011', '2010',
       '2009', '2008', '2007', '2006', '2005', '2004', '2003', '2002', '2001',
       '2000', '1999'],
      dtype='object')
In [64]:
trace1 = Scatter(
    x=[int(x) for x in dfc.columns],
    y=dfc.loc["乡村就业人员(万人)",:].values
)
In [65]:
城镇就业人员 = Scatter(
    x=[int(x) for x in dfc.columns],
    y=dfc.loc["城镇就业人员(万人)",:].values
)
乡村就业人员 = Scatter(
    x=[int(x) for x in dfc.columns],
    y=dfc.loc["乡村就业人员(万人)",:].values
)

py.offline.plot([城镇就业人员, 乡村就业人员],filename = '输出中文.html')
Out[65]:
'输出中文.html'
In [69]:
pd.to_datetime('01/01/1999', format="%m/%d/%Y")
Out[69]:
Timestamp('1999-01-01 00:00:00')
In [71]:
[pd.to_datetime('01/01/{y}'.format(y=x), format="%m/%d/%Y") for x in dfc.columns.values]
Out[71]:
[Timestamp('2018-01-01 00:00:00'),
 Timestamp('2017-01-01 00:00:00'),
 Timestamp('2016-01-01 00:00:00'),
 Timestamp('2015-01-01 00:00:00'),
 Timestamp('2014-01-01 00:00:00'),
 Timestamp('2013-01-01 00:00:00'),
 Timestamp('2012-01-01 00:00:00'),
 Timestamp('2011-01-01 00:00:00'),
 Timestamp('2010-01-01 00:00:00'),
 Timestamp('2009-01-01 00:00:00'),
 Timestamp('2008-01-01 00:00:00'),
 Timestamp('2007-01-01 00:00:00'),
 Timestamp('2006-01-01 00:00:00'),
 Timestamp('2005-01-01 00:00:00'),
 Timestamp('2004-01-01 00:00:00'),
 Timestamp('2003-01-01 00:00:00'),
 Timestamp('2002-01-01 00:00:00'),
 Timestamp('2001-01-01 00:00:00'),
 Timestamp('2000-01-01 00:00:00'),
 Timestamp('1999-01-01 00:00:00')]
In [72]:
dfc.columns
Out[72]:
Index(['2018', '2017', '2016', '2015', '2014', '2013', '2012', '2011', '2010',
       '2009', '2008', '2007', '2006', '2005', '2004', '2003', '2002', '2001',
       '2000', '1999'],
      dtype='object')
In [75]:
import plotly as py
import plotly.graph_objs as go
import pandas as pd
城镇就业人员=go.Scatter(
x=[pd.to_datetime('01/01/{y}'.format(y=x), format="%m/%d/%Y")for x in dfc.columns],
y=dfc.loc["城镇就业人员(万人)",:].values,
    name="城镇就业人员"
)
乡村就业人员=go.Scatter(
x=[pd.to_datetime('01/01/{y}'.format(y=x), format="%m/%d/%Y")for x in dfc.columns],
y=dfc.loc["乡村就业人员(万人)",:].values,
             name="乡村就业人员")
data=[城镇就业人员,乡村就业人员]
layout = dict(
    title='城乡就业人员数量',
    xaxis=dict(
        rangeselector=dict(
            buttons=list([
                dict(count=3,
                     label='3年',
                     step='year',
                     stepmode='backward'),
                dict(count=5,
                     label='5年',
                     step='year',
                     stepmode='backward'),
                dict(count=10,
                    label='10年',
                    step='year',
                    stepmode='todate'),
                dict(count=20,
                    label='20年',
                    step='year',
                    stepmode='backward'),
                dict(step='all'),
            ])),       rangeslider=dict(bgcolor="#70EC57"),
        type='date'
    )
)
                     
fig = dict(data=data, layout=layout)
py.offline.plot(fig,filename='Slide.html')
Out[75]:
'Slide.html'
In [ ]: