python 데이터 분석 매트릭스 - 약국 판매 데이터 분석

5462 단어 필기
import pandas as pd

fileNameStr='./    2018     .xlsx'
xls = pd.ExcelFile(fileNameStr, dtype='object')
salesDf = xls.parse('Sheet1',dtype='object')

print(salesDf.head())
print(salesDf.shape)

#  :           
colNameDict = {'    ':'    '}

'''
inplace=False,        ,              ,
   inplace False
inplace=True,        
'''
salesDf.rename(columns = colNameDict,inplace=True)
print(salesDf.head())

print('
',salesDf.shape) # ( , ) #how='any' salesDf=salesDf.dropna(subset=[' ',' '],how='any') print('
',salesDf.shape) # ( ) salesDf[' '] = salesDf[' '].astype('float') salesDf[' '] = salesDf[' '].astype('float') salesDf[' '] = salesDf[' '].astype('float') print('

',salesDf.dtypes) ''' : , :timeColSer , Series : , Series ''' def splitSaletime(timeColSer): timeList=[] for value in timeColSer: # 2018-01-01 , :2018-01-01 dateStr=value.split(' ')[0] timeList.append(dateStr) # Series timeSer=pd.Series(timeList) return timeSer # “ ” timeSer=salesDf[' '] # , dateSer=splitSaletime(timeSer) salesDf[' '] = dateSer salesDf[' '] = pd.to_datetime(salesDf[' '],format='%Y-%m-%d', errors='coerce') print('

',salesDf.dtypes) print('
',salesDf.shape) # ( , ) #how='any' salesDf=salesDf.dropna(subset=[' ',' '],how='any') print('
',salesDf.shape) ''' by: ascending=True , ascending=True na_position=True , , ''' # salesDf=salesDf.sort_values(by=' ', ascending=True, na_position='first') # (index): , 0 N salesDf=salesDf.reset_index(drop=True) # : # querySer=salesDf.loc[:,' ']>0 # print(' :',salesDf.shape) salesDf=salesDf.loc[querySer,:] print(' :',salesDf.shape) ''' : , # ( , ), , 1 , ''' kpi1_Df=salesDf.drop_duplicates( subset=[' ', ' '] ) # : totalI=kpi1_Df.shape[0] print(' =',totalI) kpi1_Df=kpi1_Df.reset_index(drop=True) # 2 : # startTime=kpi1_Df.loc[0,' '] # endTime=kpi1_Df.loc[totalI-1,' '] # 3 : # daysI=(endTime-startTime).days # : “//” # , 9//2 4 monthsI=daysI//30 print(' :',monthsI) kpi1_I=totalI // monthsI print(' 1: =',kpi1_I) # totalMoneyF=salesDf.loc[:,' '].sum() # monthMoneyF=totalMoneyF / monthsI print(' 2: =',monthMoneyF) ''' totalMoneyF: totalI: ''' pct=totalMoneyF / totalI print(' :',pct) import matplotlib.pyplot as plt #plt.plot([,kpi1_Df[' ']) # , , groupDf=salesDf # 1 : (index) groupDf.index=groupDf[' '] groupDf.head() # 2 : gb=groupDf.groupby(groupDf.index.month) # 3 : , mounthDf=gb.sum() print(mounthDf) plt.plot(mounthDf.index,mounthDf[' ']) plt.plot(mounthDf.index,mounthDf[' '])
                                                         
0  2018-01-01          001616528  236701    VC       6  82.8     69
1  2018-01-02          001616528  236701             1    28  24.64
2  2018-01-06         0012602828  236701             2  16.8     15
3  2018-01-11      0010070343428  236701             1    28     28
4  2018-01-15        00101554328  236701             8   224    208
(6578, 7)
                                                                   
0  2018-01-01          001616528  236701    VC       6  82.8     69
1  2018-01-02          001616528  236701             1    28  24.64
2  2018-01-06         0012602828  236701             2  16.8     15
3  2018-01-11      0010070343428  236701             1    28     28
4  2018-01-15        00101554328  236701             8   224    208

         (6578, 7)

        (6575, 7)

        :
          object
         object
         object
         object
        float64
        float64
        float64
dtype: object

        :
         datetime64[ns]
                object
                object
                object
               float64
               float64
               float64
dtype: object

         (6575, 7)

        (6549, 7)
      : (6549, 7)
      : (6506, 7)
     = 5342
   : 6
    1:      = 890
    2:      = 50668.3516667
   : 56.909417821
                               
                               
1     2527.0  53561.6  49461.19
2     1858.0  42028.8  38790.38
3     2225.0  45318.0  41597.51
4     3005.0  54296.3  48787.84
5     2225.0  51263.4  46925.27
6     2328.0  52300.8  48327.70
7     1483.0  32568.0  30120.22

좋은 웹페이지 즐겨찾기