0% found this document useful (0 votes)
19 views23 pages

Hashit 12 A File

The document contains information about a student named Harshit Prahari who is in 12th class A with roll number 17. It then provides 20 questions and answers related to creating and manipulating pandas Series and DataFrames. Key operations covered include creating Series and DataFrames from various data structures, accessing attributes like name, index, columns, dtypes, using functions like head(), tail(), insert(), delete() etc.

Uploaded by

SHASHANK RAJPUT
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views23 pages

Hashit 12 A File

The document contains information about a student named Harshit Prahari who is in 12th class A with roll number 17. It then provides 20 questions and answers related to creating and manipulating pandas Series and DataFrames. Key operations covered include creating Series and DataFrames from various data structures, accessing attributes like name, index, columns, dtypes, using functions like head(), tail(), insert(), delete() etc.

Uploaded by

SHASHANK RAJPUT
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 23

NAME = Harshit Prahari

th
Class = 12 A

Rollno = 17

Sub = informatics practices


SERIES
Q1 create an empty series
import pandas as pd
a=pd.Series()
print(a)

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]

Q7 use dtype function


print(s.dtype)

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

Q10 use ndim function


print(s.ndim)

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)

Q8 use columns function


print(b.columns)

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

Q10 use dtype function


print(b.dtypes)

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

Q14 use empty function


print(b.empty)

output:-
False
Q15 use count function
print(b.count())

output:-
0 2

Q16 use T function


print(b.T)

output:-
0 1
0 harshit jagjot
Q17 use head function
print(b.head())
output:-
name
0 harshit
1 jagjot

Q18 use tail function


print(b.tail())

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

You might also like