\n3<\/td>\n | 44<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n dtype : int 32<\/p>\n \u2192 Creation of Series from Dictionary: We can create a series by specifying indexes and values through a dictionary as:<\/p>\n >>>dict 1 = { ‘Uttar Pradesh’ : ‘Lucknow’, ‘Rajasthan’ : ‘Jaipur’} \n>>> print (diet 1) {‘Uttar Pradesh’: ‘Lucknow’, ‘Rajasthan’: ‘Jaipur’} \n>>> Series 1 = pd.Series (diet 1) \n>>> print (series 1)<\/p>\n Output: \nUttar Pradesh\u00a0 Lucknow \nRajasthan\u00a0 Jaipur \ndtype: object<\/p>\n \u2192 Accessing Elements of a Series: There are two common ways for accessing the elements of a series: Indexing and Slicing.<\/p>\n \u2192 Indexing: Indexing in series is similar to that for NumPy arrays, and is used to access elements in a series. Indexes are of two types: positional index and labelled index. Positional index takes . an integer value that corresponds to its position in the series starting from 0, whereas labelled index takes any user-defined label as index.<\/p>\n Example: \n>>> seriesNum = pd. Series ([ 11,22,33 ] ) \n>>> seriesNum [1] \nHere, the value 30 is displayed for the positional index 2.<\/p>\n \u2192 Slicing: This is similar to slicing used with NumPy arrays. We can define which part of the series is to be sliced by specifying the start and end parameters [start: end] with the series name. When we use positional indices for slicing, the value at the endindex position is excluded, i.e., only (end – start) number of data values of the series are extracted.<\/p>\n Example: \n>>> seriesCapState = pd.Series([‘Dispur’, ‘Patna’, ‘Panaji’], index=[‘Assam’, ‘Bihar’, ‘Goa’]) \n>>> seriesCapState[1:2] Bihar Patna dtype: object<\/p>\n Here, only data values at indices 1 is displayed i.e. excludes the value at index position 2.<\/p>\n \u2192 Attributes of Series: We can access certain properties called attributes of a series by using that property with the series name.<\/p>\n \n\n\nAttribute Name<\/td>\n | Purpose<\/td>\n<\/tr>\n | \nname<\/td>\n | assigns a name to the series<\/td>\n<\/tr>\n | \nindex.name<\/td>\n | assigns a name to the index of the series<\/td>\n<\/tr>\n | \nvalues<\/td>\n | prints a list of the values in the series<\/td>\n<\/tr>\n | \nsize<\/td>\n | prints the number of values in the series object<\/td>\n<\/tr>\n | \nempty<\/td>\n | prints True if the series is empty, and False otherwise<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n \u2192 Methods of Series:<\/p>\n \n\n\nHead(n)<\/td>\n | Returns the first n members of the series. If the value for n is not passed, then by default n takes 5 and the first five members are displayed.<\/td>\n<\/tr>\n | \nCount ( )<\/td>\n | Returns the number of non-NaN values in the series.<\/td>\n<\/tr>\n | \nTail (n)<\/td>\n | Returns the last n members of the series. If the value for n is not passed, then by default n takes 5 and the last five members are displayed.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n \u2192 Mathematical Operations on Series:<\/p>\n \u2192 Addition: We can use the’+’ Operator or add() method of series to perform addition between two series objects.<\/p>\n \u2192 Subtraction: We can use the Operator or sub() method of series to perform subtraction between two series objects.<\/p>\n \u2192 Division: We can use the’\/’ Operator or div() method of series to perform division between two series objects.<\/p>\n \u2192 Multiplication: We can use the ‘*’ Operator or mul() method of series to perform multiplication between two series objects.<\/p>\n \u2192 Exponential Power: We can use the ‘**’ Operator or pow() method of series to put each element of passed series as exponential power of caller series and return the results.<\/p>\n \u2192 DataFrame Data Structure: A DataFrame is a two-dimensional labelled data structure like a table of MySQL. It contains rows and columns, and therefore has both a row and column index. The row index is known as index and the column index is called the column-name.<\/p>\n \u2192 Creation of DataFrame: There are a number of ways to create a DataFrame. Some of them are listed in this section.<\/p>\n \u2192 Creation of an empty DataFrame: An empty DataFrame can be created as follows:<\/p>\n >>> import pandas as pd \n>>> dFrameEmt = pd. DataFrame () \n>>> dFrameEmt<\/p>\n Output: \nEmpty DataFrame \nColumns: [ ] ‘ \nIndex: [ ]<\/p>\n \u2192 Creation of DataFrame from NumPy ndarrays: Consider the following three NumPy ndarrays. Let us create a simple DataFrame without any column labels, using a single ndarray:<\/p>\n >>> import numpy as np \n>>> arrayl = np.array([11,22,33]) \n>>> array2 = np. array ( [ 110,210,310] ) \n>>> array3 = np.array([-100,-20 0,-300, -400]) \n>>> dFrame4 = pd.DataFrame(arrayl) \n>>> dFrame4<\/p>\n Output: \n0 11 \n1 22 \n2 33<\/p>\n \u2192 Creation of DataFrame from List of Dictionaries: We can create DataFrame from a list of Dictionaries as:<\/p>\n >>> listDict = [ { ‘a’ : 11, ‘b’:22}, { ‘a’:5,’b’:10, ‘c’:20 } ] . \n>>> dFrameListDict = pd.DataFrame(listDict) \n>>> dFrameListDict<\/p>\n Output:<\/p>\n \n\n\n<\/td>\n | a<\/td>\n | b<\/td>\n | c<\/td>\n<\/tr>\n | \n0<\/td>\n | 11<\/td>\n | 22<\/td>\n | NaN<\/td>\n<\/tr>\n | \n1<\/td>\n | 5<\/td>\n | 10<\/td>\n | 20.0<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n \u2192 Creation of DataFrame from Dictionary of Lists: DataFrames can also be created from a dictionary of lists.<\/p>\n >>> dictForest = { ‘State’ : [ ‘Kanpur’,’Delhi’, ‘Udaipur’], ‘GArea’: [96838, 7583,44552],’VDF’ : [3197, 4.42, 2563]} \n>>> dFrameForest= pd.DataFrame(dictForest) \n>>> dFrameForest \nOutput:<\/p>\n \n\n\n<\/td>\n | State<\/td>\n | GArea<\/td>\n | VDF<\/td>\n<\/tr>\n | \n0<\/td>\n | Kanpur<\/td>\n | 96838<\/td>\n | 3197.00<\/td>\n<\/tr>\n | \n1<\/td>\n | Delhi<\/td>\n | 7583<\/td>\n | 4.42<\/td>\n<\/tr>\n | \n2<\/td>\n | Udaipur<\/td>\n | 44552\u2022<\/td>\n | 2563.00<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n \u2192 Creation of DataFrame from Dictionary of Series: A dictionary of series can also be used to create a DataFrame as:<\/p>\n >>> ResultSheet= { \n‘Rohit’: pd.Series([80, 92, 87], index=[‘English’,’Science’,’Maths’]), \n‘Ayush’: pd.Series([72, 81, 94], index=[‘English’,’Science’,’Maths’]), \n‘Priya’: pd.Series([84, 86, 78], index=[‘English’,’Science’,’Maths’]), \n>>> ResultDF = pd.DataFrame(ResultSheet) \n>>> ResultDF<\/p>\n Output:<\/p>\n \n\n\n<\/td>\n | Rohit<\/td>\n | Ayush<\/td>\n | Priya<\/td>\n<\/tr>\n | \nEnglish<\/td>\n | 80<\/td>\n | 92<\/td>\n | 87<\/td>\n<\/tr>\n | \nScience<\/td>\n | 72<\/td>\n | 81<\/td>\n | 94<\/td>\n<\/tr>\n | \nMaths<\/td>\n | 84<\/td>\n | 86<\/td>\n | 78<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n \u2192 Operations on Rows and Columns in DataFrames:<\/p>\n \u2192 Adding a New Column to a DataFrame: We can easily add a new column to a DataFrame.<\/p>\n \u2192 Adding a New Row to a DataFrame: We can add a new row to a DataFrame using the DataFrame.loc[] method.<\/p>\n \u2192 Deleting Rows or Columns from a DataFrame: We can use the DataFrame.dropO method to delete rows and columns From a DataFrame.<\/p>\n \u2192 Renaming Row Labels of a DataFrame: We can change the labels of rows and columns in a DataFrame using the DataFrame. rename() method.<\/p>\n \u2192 Renaming Column Labels oF a DataFrame: To alter the column names of ResultDF, we can again use the rename() method.<\/p>\n \u2192 Accessing DataFrames Element through Indexing: Data elements in a DataFrame can be accessed using indexing. There are two ways of indexing DataFrames: Label Based Indexing and Boolean Indexing.<\/p>\n \u2192 Label Based Indexing: There are several methods in Pandas to implement label based indexing. DataFrame.loc[] is an important method that is used for label based indexing with DataFrames.<\/p>\n \u2192 Boolean Indexing: In boolean indexing, we can select the subsets of data based on the actual values in the DataFrame rather than their row\/column labels. Thus, we can use conditions on column names to filter data values.<\/p>\n \u2192 Accessing DataFrames Element through Slicing: We can use slicing to select a subset of rows and\/or columns from a DataFrame. To retrieve a set of rows, slicing can be used with rovy labels.<\/p>\n \u2192 Attributes of DataFrames:<\/p>\n \n\n\nAttribute Name<\/td>\n | Purpose<\/td>\n<\/tr>\n | \nDataFrame.index<\/td>\n | to display row labels<\/td>\n<\/tr>\n | \nDataFrame.columns<\/td>\n | to display column labels<\/td>\n<\/tr>\n | \nDataFrame.dtypes<\/td>\n | to display data type of each column in the dataframe<\/td>\n<\/tr>\n | \nDataFrame.values<\/td>\n | to display a NumPy ndarray having all the values in the dataframe, without the axes labels<\/td>\n<\/tr>\n | \nDataFrame.shape<\/td>\n | to display a tuple representing the dimensionality of the dataframe<\/td>\n<\/tr>\n | \nDataFrame.size<\/td>\n | to display a tuple representing the dimensionality of the dataframe<\/td>\n<\/tr>\n | \nDataFrame.<\/td>\n | to transpose the dataframe, means, row indices and column labels of the dataframe replace each other’s position<\/td>\n<\/tr>\n | \nDataFrame.head(n)<\/td>\n | to display the first n rows in the dataframe<\/td>\n<\/tr>\n | \nDataFrame.tail(n)<\/td>\n | to display the last n rows in the dataframe<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n | | | | | | |