Python data processing tools using method collation

Source: Internet
Author: User

#Create a Dataframe type of data structure from a CSV file>>>df=pd.read_csv ("Xxx.csv")#shape and length of the Dataframe type>>>Df.shape (38, 39)>>>Len (DF)38#headings and data types for each column>>>Df.columns>>>Df.dtypes#Index>>>Df.indexrangeindex (Start=0, stop=38, step=1)#Convert dataframe to numpy array>>>df.values#View Variable Types>>>type (DF)<class 'Pandas.core.frame.DataFrame'>#get a column of dataframe (the resulting data type is series)>>>type (DF)<class 'Pandas.core.frame.DataFrame'>>>> col=df['104']>>>type (col)<class 'pandas.core.series.Series'>#properties similar to Dataframe in series>>>Col.shape (38,)>>>Col.valuesarray ([301, 1051, 1657, 1852, 2057, 2258, 2938, 3418, 3718, 3938, 4148, 4568, 5068])>>>Col.indexrangeindex (Start=0, stop=38, step=1)>>>Col.name'104'#intercept the last few elements>>> col[-2:]36 6553637 65536Name:104, Dtype:int64>>> Type (col[-2:])<class 'pandas.core.series.Series'>#symbols of the Dataframe>>>np.sign (DF)>>> last_col=df.columns[-1]>>>np.sign (Df[last_col])#Head (take the first few lines) and tail (take a few lines)>>> Df.head (2)>>> Df.tail (2)#find a row of data by index>>> last_col=df.index[-1]>>>Last_col>>>Df.iloc[last_col]#find a column of data for a row by index>>> Df.iloc[2:9]#Iloc and IAT function the same>>> df.iloc[2,3]>>> df.iat[2,3]#Logical Lookup>>> df[df>Df.mean ()]#Statistical Calculations#Description Information>>>Df.describe ()#number of non-empty data>>>Df.count ()#average Absolute deviation (similar to standard deviation)>>>Df.mad ()#Number of median>>>Df.median ()#Minimum Value>>>df.min ()#Maximum Value>>>Df.max ()#The majority of>>>Df.mode ()#Standard deviation>>>df.std ()#Variance>>>Df.var ()#skewness coefficient (skewness, which indicates the degree of symmetry of the data)>>>Df.skew ()#Peak state function (Kurtosis, which indicates the degree of flattening of the data distribution graph)>>>Df.kurt ()#generate dataframe with a python dictionary>>> DF=PD. DataFrame ({'Weather':['Cold',' Hot'],' Food':['Soup','Ice Cream']})>>>DF Food Weather0 Soup Cold1Ice cream Hot#Group an attribute by type>>> Group=df.groupby ('Weather')>>> forName,groinchGroup: ...Print(name) ...Print(GRO) ... cold food weather0 soup Cold2Cake Coldhot Food weather1Ice cream Hot3Bread Hot>>>Group<pandas.core.groupby.groupby.dataframegroupby Object at 0x7f110c24d1d0>#first row, last line, average of each group>>> Group=df.groupby ('Weather')>>>Group.first () Food priceweather Cold Soup1Hot ice Cream2>>>group.last () food priceweather cold Cake3Hot Bread4>>>Group.mean () Priceweather Cold2 Hot3#View Grouping>>> G=df.groupby (['Weather',' Food'])>>>g.groups{(' Hot','Bread'): Int64index ([3], dtype='Int64'), ('Cold','Cake'): Int64index ([2], dtype='Int64'), (' Hot','Ice Cream'): Int64index ([1], dtype='Int64'), ('Cold','Soup'): Int64index ([0], dtype='Int64')}#Append attributes for grouping>>>G.agg ([Np.mean]) Price meanweather food Cold cake3Soup1Hot Bread4Ice Cream2#Intercept a few lines of data and connect>>> D=pd.concat ([df[:2],df[3:]])>>>D>>> D=pd.concat ([df[:2],df[3:]])>>>d food price Weather0 soup1Cold1 Ice Cream 2 Hot3 Bread 4 Hot>>> D.append (df[3:]) Food price Weather0 Soup1Cold1 Ice Cream 2 Hot3 Bread 4 Hot3 Bread 4 Hot

Python data processing tools using method collation

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.