pandas is constructed based on the module NumPy containing make faster and easier data analysis, and data structures of the operating tool, the most common data structures are: the sequence data block and DataFrame Series, Series similar to the one-dimensional array of numpy, similar to the relationship a table; and DataFrame similar to the two-dimensional table.
>>> import pandas as pd >>> from pandas import Series,DataFrame
A, pandas data type
With dtype property to display data element type, pandas dtype mainly the following:
- object: string type indicates
- int: an integer of type
- float: floating point representation type
- datetime: indicates the time type
- bool: Boolean representation
- category: Category
1, view data types
View data box, type a column of data:
df['col_name'].dtypes
2, data type conversion
astype (dtype) function for converting the data frame to a specific type of column, pandas DTYPE may be a supported type may be numpy.dtype, Python type may be:
Column to change the data frame to a string, str, python type, 'object' is pandas string types supported:
df['col_name'].astype(str) df['col_name'].astype('object')
3, other types of conversion functions
Pandas using functions provided as to_numeric (), to_datetime ()
Second, the sequence
Series is an ordered set of data and associated index composition, the elements can be accessed by an index Series object.
1, create a sequence
Using only one set of data can be generated simplest Series, at this time the index is sequentially incremented from 0 integer:
obj=Series([4,7,-5,3])
Index sequence and the value can be viewed by the index attribute values and object Series:
obj.values ## array([4,7,-5,3]) obj.index ## Int64Index([0,1,2,3])
You can use the list to create a custom sequence:
obj=Series([4,7,-5,3],index=['d','b','a','c'])
If the data is stored in a Python dictionary structure can also be created directly by Series dictionary:
>>> sdata = {'b': 12, 'a': 13, 'd': 14, 'c': 10} >>> sd=pd.Series(sdata) b 12 a 13 d 14 c 10 dtype: int64
2, the sequence element access
To access the elements of the sequence by an index, and can be modified value sequence elements
sd [ ' a ' ] = 4
Reference documents: