Hashit 12 A File
Hashit 12 A File
th
Class = 12 A
Rollno = 17
output:-
Series([], dtype: float64)
Q2 create a series using tuple
import pandas as pd
t=(12,23,5,42,3)
s=pd.Series(t)
print(s)
output:-
0 12
1 23
2 5
3 42
4 3
dtype: int64
Q3 create a series using list
import pandas as pd
l=(11,22,3,33,44,67)
q=pd.Series(l)
print(q)
output:-
0 11
1 22
2 3
3 33
4 44
5 67
dtype: int64
Q4 create a series using dictionary
import pandas as pd
d={'a':1,'b':2}
w=pd.Series(d)
print(w)
output:-
a 1
b 2
dtype: int64
Q5 create a series using ndarray
import pandas as pd
import numpy as np
a=np.array([1,2,3,4,5])
s=pd.Series(a)
print(s)
output:-
0 1
1 2
2 3
3 4
4 5
dtype: int32
Q6 use values function
print(s.values)
output:-
[1 2 3 4 5]
output:-
int32
Q8 use name attribute function
s.name='rollno'
print(s)
output:-
0 1
1 2
2 3
3 4
4 5
Q9 use size function
print(s.size)
output:-
Name: rollno, dtype: int32
5
output:-
1
DATAFRAME
Q1 create an empty dataframe
import pandas as pd
a=pd.DataFrame()
print(a)
output:-
Empty DataFrame
Columns: []
Index: []
Q2 create dataframe using list
import pandas as pd
l=[12,34,33,23]
b=pd.DataFrame(l)
print(b)
output:-
0
0 12
1 34
2 33
3 23
Q3 create dataframe using tuple
import pandas as pd
t=(10,20,40)
c=pd.DataFrame(t)
print(c)
output:-
0
0 10
1 20
2 40
Q4 create dataframe using dictionary
import pandas as pd
d={'name':['harsh','nakul','sahil']}
e=pd.DataFrame(d)
print(e)
output:-
name
0 harsh
1 nakul
2 sahil
Q5 create a dataframe using series
import pandas as pd
r=(23,56,78,99)
a=pd.Series(r)
b=pd.DataFrame(a)
print(b)
output:-
0
0 23
1 56
2 78
3 99
Q6 create a dataframe using ndarray
import pandas as pd
import numpy as nd
a=nd.array(['harshit','jagjot'])
b=pd.DataFrame(a)
print(b)
output:-
0
0 harshit
1 jagjot
Q7 use index function
print(b.index)
output:-
RangeIndex(start=0, stop=2, step=1)
output:-
RangeIndex(start=0, stop=1, step=1)
Q9 use axes function
print(b.axes)
output:-
[RangeIndex(start=0, stop=2, step=1),
RangeIndex(start=0, stop=1, step=1)]
0 object
output:-
dtype: object
Q11 use size function
print(b.size)
output:-
2
Q12 use shape function
print(b.shape)
output:-
(2, 1)
Q13 use ndim function
print(b.ndim)
outout:-
2
output:-
False
Q15 use count function
print(b.count())
output:-
0 2
output:-
0 1
0 harshit jagjot
Q17 use head function
print(b.head())
output:-
name
0 harshit
1 jagjot
output:-
name
0 harshit
1 jagjot
Q19 delete name column
del b['name']
print(b)
output:-
name
0 harshit
1 jagjot
Q20 insert a column
b.insert(0,'rollno',(1,2))
print(b)
output:-
rollno
0 1
1 2