Examples .com



2895600-29845 Introduction to It is?a free software written(11?January 2008) for?python programming language?for data manipulation and analysis. The name is derived from the term "panel data". It offers data structures and operations for data manipulation. Pandas allows importing data of various file formats such as csv, excel etc. It is developed by Wes McKinney as a high performance, flexible tool to perform?quantitative analysis?on financial data.2139950161290?Born on:20 March 1985SERIES:Series is a one-dimensional labelled array capable of holding data of any type (integer, string, float, python objects, etc.). The axis labels are collectively called index.A series can be created using various inputs like ?ArrayDictScalar value or constantExamples Program to create series:import pandas as pds = pd.Series()print(s)Output: Series([], dtype: float64)Program to create series from ndarray:import pandas as pdimport numpy as npdata = np.array(['a','b','c','d'])s = pd.Series(data)print(s)Output:0 a1 b2 c3 ddtype: objectWe did not pass any index, so by default, it assigned the indexes ranging from 0 to?len(data)-1, i.e., 0 to 3.import pandas as pdimport numpy as npdata = np.array(['a','b','c','d'])s = pd.Series(data,index=[100,101,102,103])print(s)Its?output?is as follows ?100 a101 b102 c103 ddtype: objectWe passed the index values here. Now we can see the customized indexed values in the output.Create a Series from dict:A?dict?can be passed as input and if no index is specified, then the dictionary keys are taken in a sorted order to construct index. If?index?is passed, the values in data corresponding to the labels in the index will be pulled out.import pandas as pdimport numpy as npdata = {'a' : 0., 'b' : 1., 'c' : 2.}s = pd.Series(data)print(s)Its?output?is as follows ?a 0.0b 1.0c 2.0dtype: float64Dictionary keys are used to construct index.Create a Series from scalar values:import pandas as pdimport numpy as nps = pd.Series(5, index=[0, 1, 2, 3])print(s)Its?output?is as follows ?0 51 52 53 5dtype: int64Accessing Data from Series with Positionimport pandas as pds = pd.Series([1,2,3,4,5],index = ['a','b','c','d','e'])#retrieve the last three elementprint(s[::])#prints allprint(s[::2])#prints all but alternate step=2print(s[::-1])#prints in reverse orderprint(s[1:3:])#prints from index 1 to 2print(s[3:])#prints from index 3 to endprint(s[:3])#prints from 0 to 2print(s[-3:])#prints last 3print(s[-2:])#prints last 2Output:a 1b 2c 3d 4e 5dtype: int64a 1c 3e 5dtype: int64e 5d 4c 3b 2a 1dtype: int64b 2c 3dtype: int64d 4e 5dtype: int64a 1b 2c 3dtype: int64c 3d 4e 5dtype: int64d 4e 5dtype: int64Retrieve Data Using Label (Index):import pandas as pds = pd.Series([1,2,3,4,5],index = ['a','b','c','d','e'])print(s['a'])#prints with label aprint(s[['a','b','c','d','e']])#prints all print(s[['a','b','c']])#prints with label a,b and cOutput:1a 1b 2c 3d 4e 5dtype: int64a 1b 2c 3dtype: int64 ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download