import pandas as pd
path= r"E:\北风\数据科学脚本\Python_book\5Preprocessing\sale.csv"
info= open ( path)
info_1= pd. read_csv( info)
print ( info_1)
info_1[ "date" ] = pd. to_datetime( info_1[ "year" ] )
print ( info_1. head( 10 ) )
year market sale profit
0 2010 东 33912 2641
1 2010 南 32246 2699
2 2010 西 34792 2574
3 2010 北 31884 2673
4 2011 东 31651 2437
5 2011 南 30572 2853
6 2011 西 34175 2877
7 2011 北 30555 2749
8 2012 东 31619 2106
9 2012 南 32443 3124
10 2012 西 32103 2593
11 2012 北 31744 2962
year market sale profit date
0 2010 东 33912 2641 1970-01-01 00:00:00.000002010
1 2010 南 32246 2699 1970-01-01 00:00:00.000002010
2 2010 西 34792 2574 1970-01-01 00:00:00.000002010
3 2010 北 31884 2673 1970-01-01 00:00:00.000002010
4 2011 东 31651 2437 1970-01-01 00:00:00.000002011
5 2011 南 30572 2853 1970-01-01 00:00:00.000002011
6 2011 西 34175 2877 1970-01-01 00:00:00.000002011
7 2011 北 30555 2749 1970-01-01 00:00:00.000002011
8 2012 东 31619 2106 1970-01-01 00:00:00.000002012
9 2012 南 32443 3124 1970-01-01 00:00:00.000002012
import matplotlib. pyplot as plt
import numpy as np
plt. plot( info_1[ "sale" ] , info_1[ "date" ] )
plt. xticks( rotation= 45 )
plt. xlabel( "money" )
plt. ylabel( "year" )
plt. title( "year-sales" )
plt. show( )
fig= plt. figure( )
ax1= fig. add_subplot( 4 , 4 , 1 )
ax2= fig. add_subplot( 4 , 4 , 3 )
ax3= fig. add_subplot( 4 , 4 , 8 )
ax1. plot( np. random. randint( 1 , 5 , 5 ) , np. arange( 5 ) )
ax2. plot( np. arange( 10 ) * 3 , np. arange( 10 ) )
plt. show( )
fig= plt. figure( figsize= ( 6 , 3 ) )
info_1[ "Year" ] = info_1[ "date" ] . dt. year
plt. figure( figsize= ( 6 , 3 ) )
plt. plot( info_1[ 0 : 5 ] [ "year" ] , info_1[ 0 : 5 ] [ "sale" ] , c= "red" )
plt. plot( info_1[ 5 : 10 ] [ "year" ] , info_1[ 5 : 10 ] [ "sale" ] , c= "blue" )
plt. show( )
<matplotlib.figure.Figure at 0x1e03f6b7048>