Series Methods & Properties

Introduction
Pandas Series is the block for handling one dimensional data [ single column ] . Just like a single column in a spreadsheet or a list of numbers
It is array- like object that can hold data of any type ( integers , float , strings ,etc ) along with cutom labels called indices
Each value has an index , making it easy to access , filter and slice
Remember : Multiple rows but in single columns
Let’s explore what Series is, why it’s important, and how to use its basic methods for data analysis.
Creating a Series
Steps :
Import pandas
Use pandas method named Series Example : Syntax : new_variable = pd.Series(iterable)
Execute and get the output in single column
import pandas as pd
data = [2, 4, 6, 8]
s = pd.Series(data)
print(s)
Output :
0 2
1 4
2 6
3 8
dtype: int64
Another ways :
# From a list
numbers = pd.Series([10, 20, 30])
# From a dictionary
marks = pd.Series({'English': 85, 'Math': 90, 'Science': 95})
# From a scalar
zeroes = pd.Series(0, index=[1,2,3])
Basic methods in Series :
Index() : To Know the index ------ All the characters are present in string format so dtype='object'
Count() : Output same as size but size is property and count is method
value_counts() : gives the count of values present in data
unique() : to get the unique data in the array format
nunique () : to get the count of unique data present in data
isnull() : Get the True for null for else False
notnull() : Get the False for null else True
nlargest() : Orders data in descending order --- variable_name.nlargest(1) : Returns only first largest value
nsmallest () : Orders data in ascending order -- variable_name.nsmallest(1) : Returns only first smallest value
head () : Top n rows by default 5
tail() : Bottom n rows by default 5
sample() : Random n rows by default 1
describe() : describes mathematical information / statistics format -- count,mean,std,min,25%,50%,75%,max
info() : describes information about data -- Non-Null , Count , dtype
sum() : Adds the data
min () : Min of data
max() : Max of data
dropna () : Blank spaces or None value are removed , it will also drop the index
fillna () : Blank spaces or None value are filled with value .
replace() : Replace old value with new value --- If new value not given replaces with random value and generates warning
sort_values () : sort the data based on values
sort_index() : sort the data based on index
duplicated() : #Output in boolean like True and false format --- > if duplicate element returns True else False
drop_duplicated() : To drop all duplicates we going with the drop duplicates
drop () : To drop multiple elements or single element variable_name.drop(position) example : d.drop(0) # to delete 1 particular number ----> variable_name.drop([[position1,position 2,... ]]) # when we want to delete multiple numbers
pop() : to remove single element --- > Cannot remove multiple elements
concat() : Add the data one below other ----> Limitation : concat multiple rows in series in single code —→Repeated indexing ---- >To continue the indexing use ignore_index property , set ignore_index=True
To fetch particular column in data : Using Indexing : variable_name[columnindex] & Slicing : variable_name[starting_index of column:ending_index of column:step_value]
Basic proprties in Series :
Index : Changing the index parameter
Name : Changing the name parameter : name =" Any name "
Size : To know the size of data --- To know how many data is present
Shape : To know the shape of data
ndim : To know the dimension of data
values : To get the values
dtype : Returns the datatype of data
empty : Return false if data is not present in column else True
axes : --- Returns the axes --- if present : [Index(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i'], dtype='object')] --- if not present : [RangeIndex(start=0, stop=4, step=1)]
hasnas : if blank spaces or None value are present True or else false
Key Takeaways
Series is a basic, one-dimensional data structure in Pandas.
Easy to create, inspect, filter, and use!
Learn Series before diving into more complex DataFrames.