Pandas-Series

Pandas contains advanced data structures and manipulation tools that make data analysis faster and easier. Pandas is built on numpy.


Two main data structures: Series and DataFrame.
Series: An object similar to a one-bit array, consisting of a set of data and a set of data labels associated with it.
Generate Series:
1. The simplest Series can be produced from only a one-dimensional list:
obj = Series([-1, 5, 7, 9])
		0   -1
		1    5
		2    7
		3    9
		dtype: int64
            
	  2. Create a Series from a dictionary
		At this time, the key in the dictionary is the index in the Series, and the value in the dictionary is the value in the Series
	    3. Create a Series with an index:
			obj2 = Series([4, 7, -5, 3],index = ['d', 'b', 'a', 'c'])

	Series common functions:
		obj.values ​​(no parentheses, common sense use function with parentheses)
		obj.index   
		Obtained its array representation and index object respectively
			如:array([-1,  5,  7,  9], dtype=int64)
			    Index(['d', 'b', 'a', 'c'], dtype='object')
                  obj['a'], obj2[['c', 'a', 'b']]: can be selected by index to change a single or a group of values ​​in the Series
		  Numpy array operations preserve the link between index and value:
			obj2[obj2 > 0] (returns the part > 0, with index and value)
			obj2 * 2
		  Check if an index exists: 'b' in obj2 (returns boolean)
                  Series() passes in a dictionary and an index array, and a Series will be created. The left side is the index array, and the right side is the corresponding value of the index array in the dictionary. If there is no corresponding value, it will return NAN (not a number)
		  pandas' notnull and isnull are used to detect missing data:
			pd.isnull(obj4) returns a Boolean value of the index value on the left of a Series
		  An important function of Series: data with different indices will be automatically aligned in arithmetic operations
			The data corresponding to the same index value of the Series finally obtained by obj3+obj4 is added, and the difference still exists, and no operation is performed.
	 	  Series name property: obj4.name = 'population'
				   obj4.index.name = 'state'
 
  
			state
			california        NaN
			ohio          35000.0
			oregon        16000.0
			texas         71000.0
			Name: population, dtype: float64
		    The index of the Series can be modified in-place by assignment: obj.index = ['Bob', 'Steve', 'Jeff', 'Ryan']

		      
 
  
 
  

		

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326641244&siteId=291194637