Pandas( Data analysis and processing library )
Import library import pandas as pd
(pandas There are two main data structures :dataframe,series.series Is a one-dimensional array ,dataframe Is a two-dimensional array .DataFrame yes Pandas A tabular data structure in , Contains an ordered set of columns , Each column can be a different value type ( numerical value , character string , Boolean type, etc ),DataFrame There are both row and column indexes , Can be seen as by Series Composition dictionary . It is an object similar to a one-dimensional array , Is a set of data ( various NumPy data type ) And a set of data tags associated with it ( Index ) form . Simple data can also be generated from only one set of data Series object )
1>pd.Series([ ]) Returns the element in the array and its index
pd.Series([ ],index=list( )) index Replace index
2>temp_dict={ }
pd.Series(temp_dict) The keys and key values in the dictionary are returned ( Index and value )
3>df.describe() Specify index
4>pd.read_csv(“ File path ”) read file
pd.read_sql(sql_sentence.connection) connection Represents a database link
5>df.ndim Data dimension
6>df.index Row index
df.columns Column index
7>df.head( ) Show header lines , default 5 that 's ok
8>df.tail( ) Show last few lines , default 5 that 's ok
9>df.info( ) Overview of relevant information : Number of rows , Number of columns , Column index , Memory
10>df.describe( ) Rapid comprehensive statistical results : count , mean value , standard deviation , Maximum , Schiff digit , minimum value
11>df.sort_values(by=" ") Sorts the specified column
12>df.loc[] Index by tag
df.iloc[] Index by location
13> Numerical operation :df.corr() Calculate the correlation coefficient ;df[‘Age’].value_counts() seek Age The number of identical numbers in this column
14> PivotTable :example.pivot(index=’’,columns=’’,values=’’),df.pivot_table(index=’’,columns=’’,values=’’,aggfunc=’’)
15> Time operation :(import datetime) First you have to create a timestamp , Then carry out relevant operations
pd.to_datetime(s),ts.month,ts.dt.month,ts.dt.day,ts.dt.weekend
16>df.assign(ration=) Add to table , The equal sign is followed by the characteristics of the data to be filled in
17>df.replace(np.nan,9,inplace=True) Replace value , Replacement of data source
18>pd.cut(x,y) take x with y Segment the interval
19>df.fillna(4) Fill missing values with numbers 4
df.isnull() Looking for missing values
20> String operation :
21>df1.sort_index(axis=1) Size sort by column index
22>df.rename(columns={},index={}) Rename row and column labels
df.columns() Modify column labels for data
df.index() Modify row labels for data
Technology