Pandas Series Flashcards
What is an Panda Series ?
Panda Series Data Structure is an One Dimensional Array ,containing a sequence of values associated with labeled index.
How to create a series in Pandas ?
import pandas as pd
s1 = pd.Series([10,25,56,78])
print(s1)
- How to print index information of pandas Series object
import pandas as pd
s1 = pd.Series([10,20,30,40])
print(s1.index)
- How to know data type of pandas series ?
import pandas as pd
s1 = pd.Series([10,20,30,40])
print(s1.dtype)
How to access data value from pandas series ?
We have three methods. s1.values s1[1] for n in s1: print(n)
- How to create an Series object with labeled index in pandas,and present the object and index ?
import pandas as pd
s2 = pd.Series([110,20,30,40],[‘a’,’b’,’c’,’d’])
print(s2) # Presenting the object
print(s2.index) # presenting the index of Series object
While creating a Series object ,it is necessary the length of values and index is same ?
Yes it is necessary no. of index and values should be same
What is the data type attribute in Series object ?
It returns a data type of object
import pandas as pd
s1 = pd.Series([10,20,30,40])
print(s1.dtype)
What is the attribute in Series object which tells no. of items in Series Object ?
import pandas as pd
s1 = pd.Series([10,20,30,40])
print(s1.index)
What is the major difference in lists and panda Series ?
In Series we have a option of labeling an index.
How multiply or add a values to Series object ?
import pandas as pd s3 = pd.Series([1,2,3,4,5]) s3 = s3 +10 print(s3) s3 = s3 *3 print(s3)
How to present multiply and add of two pandas Series values ?
import pandas as pd s3 = pd.Series([1,2,3,4,5]) s4 = pd.Series([5,4,3,2,1]) print(s3*s4) print(s3+s4)
How to use an identity operator in pandas Series ?
import pandas as pd s3 = pd.Series([1,2,3,4,5]) print(2 in s3.values) print(10 in s1) if 4 in s3.values: print('True')
How to print pandas Series object values only ?
import pandas as pd
s3 = pd.Series([1,2,3,4,5])
print(s3.values)
Create a Series object of range 100, and assign value 4 to each ?
s5 = pd.Series(4,index = range(100))
print(s5)
Create a Series object of labeled index a to f, and assighn value 4 to each ?
import pandas as pd
s5 = pd.Series(4,index = [‘a’,’b’,’c’,’d’,’e’,’f’])
print(s5)
Create a Series Object and assigh numeric values,test values greator than 10 ?
import pandas as pd
s6=pd.Series([40,2,3,50,9,90,100,5,9,4,1])
print(s6[s6>10])
print(s6 > 10)
Create a Series Object and assighn numeric values,present values only on certain condition ?
import pandas as pd
s6=pd.Series([40,2,3,50,9,90,100,5,9,4,1])
print(s6[s6>40])
Create a Series Object and assigh numeric values,test values greator than 10 ,
on this testing condition create a filter?
We have two methods.
s6=pd.Series([40,2,3,50,9,90,100,5,9,4,1])
myfilter = s6 > 40
s6[myfilter]
myfilter2=s6[s6>10]
print(myfilter2)
Create a Series Object and assigh numeric values,present values which are greator than mean of values in Series ?
import pandas as pd
s6=pd.Series([40,2,3,50,9,90,100,5,9,4,1],[‘a’,’b’,’c’,’d’,’e’,’f’,’g’,’h’,’i’,’j’,’k’])
print(s6[s6>s6.mean()])
Create a Series Object,create a dictionary,assgn dictionaty to series object,and name a Series Object ?
import pandas as pd
grades = {‘Marry’:94,’David’:80,’John’:95,’Sundy’:98}
s8=pd.Series(grades,name=’Grades’)
print(s8)
Create a Series object of Dictionaty Data Structure ?
import pandas as pd
profile = {‘ID’:123,’Name’:’Hemant’,’Sex’:’Male’,’Age’:34}
s7=pd.Series(profile) # create a Series, uses dictionary key values as index
print(s7)
print(s7[‘Name’])
Create a Series Object and name it ,assign numeric values?
import pandas as pd
s9=pd.Series([10,20,3,40],[‘a’,’b’,’c’,’d’],name=’Numeric Values’)
print(s9)
Create a Series Object and assign numeric values, check ,If mean of series is greator than 10 or not ?
import pandas as pd
s6=pd.Series([40,2,3,50,9,90,100,5,9,4,1],[‘a’,’b’,’c’,’d’,’e’,’f’,’g’,’h’,’i’,’j’,’k’])
print(s1.mean() > 10)
Create a series named grades to store grades of an Student with name ?
import pandas as pd
grades = pd.Series([120,30,40],index=[‘Hemant’,’Sundy’,’Bella’])
print(grades)
What are the parameters in pd.Series () method ?
index,names and dictionary