ImportNumPy as NPImportPandas as PD fromPandasImportSeries,dataframes=series ([1,2,3],index=['a','b','C'])Print(s)" "A 1b 2c 3dtype:int64" "Print(Np.max (s))#can perform NP operationsS.name='Rank'S.index.name='name'Print(s)#Create Dataframesdata1={'name':['a','b','C'],'Rank': [+],'score': [98,89,54]}Print(SDATA1)#Dictionarydf1=DataFrame (sdata1)Print(DF1)" "name Rank score0 a 1 981 B 2 892 c 3" "DF2=dataframe (sdata1,columns=['score','name','Rank'])Print(DF2)" "can be automatically aligned, just position change score name Rank0 98 a one-by-one B 3" "df3=dataframe (sdata1,columns=['score','name','Rank','class'],index=['1','2','3'])Print(DF3)" "class This column is missing value score name rank Class1 98 a 1 NaN2 2 NaN3 c 3 NaN" "Df4=df3.reindex (['1','2','3','4'])Print(DF4)" "re-index score name rank Class1 98.0 A 1.0 NaN2 89.0 B 2.0 NaN3 54.0 C 3.0 NaN4 nan Nan Nan nan" "Print(df4['score'])Print(df4.ix['1'])Print(df2[df2['score']>60])#returns the value of score greater than 60 in DF2" "score name Rank0 98 a all-in-one B 2" "deldf3['class']Print(DF3)#Delete class This columnsdata1={'name':['a','b','C'],'Rank': [+],'score': [98,89,54]}Print(sdata1) df3=dataframe (sdata1,columns=['score','name','Rank','class'],index=['1','2','3'])deldf3['class']Print(DF3)Print(Df3.reindex (['1','2','3','4']))Print(Df3.reindex (['1','2','3','4'],fill_value=0))#The missing value is assigned a value of 0" "score name Rank1 98 a 0 0 0" "Print(Df3.reindex (['0','1','2','3']))" "score name Rank0 nan nan NaN1 98.0 a 1.02 89.0 b 2.03 54.0 C 3.0" "Print(Df3.reindex (['0','1','2','3'],method='Bfill'))#padding Backwards" "score Name Rank0 98 a 98 a 3" "Print(Df3.drop ('1'))#Delete First rowPrint(Df3.drop ('score', Axis=1))#deletes the specified column, axis is the number of dimensions, 0 is row, and 1 is columnPrint(DF3. T# Transpose
Python Cleaning Data