# Coding:utf-8
__author__ = ' Weekyin '
Import NumPy as NP
Import Pandas as PD
Datas = Pd.date_range (' 20140729 ', periods=6)
# first create a time index, the so-called index is the ID of each row of data, you can identify the unique value of each row
Print Datas
# for a quick start, let's look at how to create a 6x4 data: The RANDN function creates a random number, the parameter represents the number of rows and columns, and dates is the index column created in the previous step
DF = PD. DataFrame (NP.RANDOM.RANDN (6, 4), Index=datas, Columns=list (' ABCD '))
Print DF
# We can also use a dictionary to create a data frame, such as creating a data frame with a column named A, an index that is automatically created as an integer
DF2 = PD. DataFrame ({' A ': Np.random.randn (6),})
Print DF2
# This is another example of a dictionary creating dataframe
DF2 = PD. DataFrame ({' A ': PD. Timestamp (' 20140729 '), ' B ': PD. Series (1),})
Print DF2
# If the length of the data in the dictionary is different, whichever is the longest, for example, there are 4 rows in column B:
DF2 = PD. DataFrame ({' A ': PD. Timestamp (' 20140729 '), ' B ': PD. Series (1, Index=list (range (4))),})
Print DF2
# You can use Dtypes to see the data formats for each row
Print Df2.dtypes
# then look at how to view the data in the data frame and see all the data
Print DF
# Use Head to see the first few rows of data (default is the first 5 rows), but you can specify the first few lines
Print Df.head ()
# View the first three rows of data
Print Df.head (3)
# Use Tail to view the following 2 rows of data
Print Df.tail (2)
# View the index of the data frame
Print Df.index
# View column names with columns
Print Df.columns
# View data values, use values
Print Df.values
# View descriptive statistics, using describe
Print Df.describe ()
# Use the type to look at the output of descriptive statistics what kind of data type--dataframe data
Print type (Df.describe ())
# use T to transpose data, i.e. row and column conversions
Print DF. T
# Sort the data and use the sort parameter to specify which column of data to sort by.
Print Df.sort (columns= ' C ')
Common methods of Pandas in Python