This is a Pandas QuickStart tutorial that is primarily geared toward new users. This is mainly for those who like "Chanping" readers, interested readers can use the other tutorial articles to step by step more complex application knowledge.
First, let's say you've installed Anaconda, now start Anaconda and start learning the examples in this tutorial. The working interface is shown below-
Test the working environment for installation of Pandas, import the related package as follows:
Import pandas as PD
import numpy as NP
import Matplotlib.pyplot as Plt
print ("Hello, Pandas")
Python
Then execute it to see if there is a problem, if normal should see the following results in the terminal output area-
Object Creation
Create a series by passing a list of values so that pandas creates a default integer index :
Import pandas as PD
import numpy as np
s = PD. Series ([1,3,5,np.nan,6,8])
print (s)
Python
After execution the output is as follows-
Runfile (' c:/users/administrator/.spyder-py3/temp.py ', wdir= ' c:/users/administrator/.spyder-py3 ')
0 1.0
1 3.0
2 5.0
3 NaN
4 6.0
5 8.0
Dtype:float64
Shell
Create dataframe using a datetime index and a tagged column by passing the NumPy array:
Import pandas as PD
import numpy as np
dates = pd.date_range (' 20170101 ', periods=7)
print ( Dates)
print ("---" *16)
= PD. Dataframe(np.random.randn (7,4), index=dates, columns=list (' ABCD '))
print (DF)
Python
After execution the output is as follows-
Runfile (' c:/users/administrator/.spyder-py3/temp.py ', wdir= ' c:/users/administrator/.spyder-py3 ')
Datetimeindex ([' 2017-01-01 ', ' 2017-01-02 ', ' 2017-01-03 ', ' 2017-01-04 ',
' 2017-01-05 ', ' 2017-01-06 ', ' 2017-01-07 ') ],
dtype= ' datetime64[ns] ', freq= ' d ')
--------------------------------
A B C D
2017-01-01-0.732038 0.329773-0.156383 0.270800
2017-01-02 0.750144 0.722037-0.849848- 1.105319
2017-01-03-0.786664-0.204211 1.246395 0.292975
2017-01-04-1.108991 2.228375 0.079700-1.738507
2017-01-05 0.348526-0.960212 0.190978-2.223966
2017-01-06-0.579689 -1.355910 0.095982 1.233833
2017-01-07 1.086872 0.664982 0.377787 1.012772
Shell
Create a dataframe by passing a dictionary that can be converted to a similar series of objects. Refer to the following sample code-
Import pandas as PD
import numpy as np
DF2 = PD. Dataframe ({' A ': 1.,
' B ': PD. Timestamp (' 20170102 '),
' C ': PD. Series (1,index=list (range (4)), dtype= ' float32 '),
' D ': Np.array ([3] * 4,dtype= ' int32 '),
' E ': PD. Categorical (["Test", "Train", "Test", "Train"]),
' F ': ' foo '}
'
print (DF2)
Python
After executing the sample code above, the output is as follows-
Runfile (' c:/users/administrator/.spyder-py3/temp.py ', wdir= ' c:/users/administrator/.spyder-py3 ')
A B C D E F
0 1.0 2017-01-02 1.0 3 Test foo
1 1.0 2017-01-02 1.0 3 train foo
2 1.0 2017-01-02 1.0 3 Test foo
3 1.0 2017-01-02 1.0 3 train foo
Shell
With the specified Dtypes, refer to the following sample code-
Runfile (' c:/users/administrator/.spyder-py3/temp.py ', wdir= ' c:/users/administrator/.spyder-py3 ')
A Float64
B datetime64[ns]
C float32
D int32
E category
F object
Dtype:object
Python
After executing the sample code above, the output is as follows-
Runfile (' c:/users/administrator/.spyder-py3/temp.py ', wdir= ' c:/users/administrator/.spyder-py3 ')
A Float64
B datetime64[ns]
C float32
D int32
E category
F Object
Dtype:object
Shell
If you use Ipython, the option to automatically enable column names (as well as public properties) is complete . The following is a subset of the properties that will be completed:
in [[]: Df2.<tab>
df2. A df2.bool
df2.abs df2.boxplot
df2.add df2. C
df2.add_prefix df2.clip
df2.add_suffix df2.clip_lower
df2.align df2.clip_upper
df2.all df2.columns
df2.any df2.combine df2.append
Df2.combine_first Df2.apply df2.compound
df2.applymap df2.consolidate
df2. D
Python
As you can see, the columns A,b,c and D auto tag are complete. E is the same. The remaining attributes are truncated for simplicity. View Data
View the data rows at the top and bottom of the frame. Refer to the following sample code-
Import pandas as PD
import NumPy as NP