Python Project File
Python Project File
List Of Programs:
1.Write code to create a series object using the python
sequence (4,6,8,10).Assume that Pandas is imported as
alias name pd.
2. Write code to create a Series object using the Python
sequence (11,21,31,41). Assume that pandas is
imported as alias name pd.
3.Write a program to create a series object using a
dictionary that stores the number of student in each
section of class 12 in your school.
4.Write a program to create a Series object that stores
the initial budget allocated(50000/each) for the four
quarter of year:Qtr1,Qtr2,Qtr3,Qtr4.
5.Consider the Series object s13 that stores the
contribution of each section, as shown below:.
6. A series object consists of around 10 rows of data.
Write a program to print First 3 rows of data.
7.Given a dictionary that stores the section names’ list as
value for’Section’ key and contribution amount’list as
value for ‘Contri’ key, create a dataframe:
Dict1={‘Section’:[‘A’,’B’,’C’,’D’],”Contri”:[16700,5600,500
0,5200]}
8.Write a program create a dataframe from 2d
list.Specify own index labels.
9.To create a dataframe to store weight,age and names
of 3 people.
10.Write a program to create a dataframe from 2d array
as shown below:
Solution of pandas:
Solution1.
1.import pandas as pd
2.import numpy as np
3.L1=[4,6,8,10]
4.S1=pd.Series(L1)
5.print(S1)
Output:
Solution2:-
1.import pandas as pd
2.import numpy as np
3.L1=[11,21,31,41]
4.S1=pd.Series(L1)
5.Print(S1)
Output:
Solution3:
Import pandas as pd
Import numpy as np
Cls12={“A”:10,”B”:20,”C”:30}
S1=pd.Series(Cls12)
Print(S1)
Output:
Solution4:
Import pandas as pd
Import numpy as np
Year={“Qtr1”:50000,”Qtr2”:50000,”Qtr3”:50000,”Qtr4”:5
00000}
S1=pd.Series(Year)
Print(S1)
Output:
Solution5:
Import pandas as pd
Import numpy as np
S1=Pd.Series(S13)
Print(S13={“A”:6700,”B”:5600,”C”:5000,”D”:5200}
s1)
Output:
Solution6:
Import pandas as pd
Import numpy as np
Data=[1,2,3,4,5,6,7,8,9,1o]
S1=pd.Series(data)
#for first three rows
First_three=s1.head(3)
Print(first_three)
Output:
Output:
Solution8:
Import pandas as pd
define the 2D list
data=[[101,113,124],[130,140,200],[115,216,217]]
df=pd.DataFrame(data,columns=[“columns1”,”column2”,
”column3”])
print(df)
Output:
Solution9:
Import pandas as pd
Data=[[58,20,”Chetan”],[55,17,”Aditya”],[60,20,”Prachi”]
]
Index=[‘A’,’B’,’C’]
df=pd.DataFrame(data,index=index,columns=[”Weight”,”
Age”,”Names”])
print(df)
Output:
Solution10:
import pandas as pd
data=[[101,113,124],[130,140,200],[115,216,217]]
df=pd.DataFrame(data,columns=[‘Column1’,’Column2’,’C
olumn3’])
print(df)
#Output:
Solution11:
Import pandas as pd
Import numpy as np
Arr1=np.array([[11,12],[13,14],[15,16]].np.int32)
Dtf2=pd.DataFrame(Arr1)
Print(Dtf2)
Output:
Solution12:
Import pandas as pd
Data=[[7916,6189,610],[8508,8208,508]]
Index=[“Andhra”,”Odisha”]
Aid=pd.DataFrame(Data,Index=Index,Columns=[“Toys”,”
Books”,”Uniform”])
Print(aid)
Output:
Solution13:
Import pandas as pd
Data=[[6189,610],[8208,508]]
Index=[“Andhra”,”Odisha”]
#to print Books and Uniform data
df_books_uniform=aid[[“Books”,”Uniform”]]
print(df_books_uniform)
#output:
Solution14:
Import pandas as pd
df_uniform=aid[[“Uniform”]]
print(df_uniform)
Output:
Solution15:
Import pandas as pd
data= [[7916,6189,610],[8508,8208,508]]
index=[“Andhra”,”Odisha”]
aid=pd.DataFrame(data,index=index,
columns=[“Toys”,”Books”,”Uniform”])
print(aid)
df1[“Laptops”]=[300,400]
print(df1)
Output:
Solution16:
Import pandas as pd
d1=[[56000,58000],[70000,68000],[75000,78000]]
index=[“ZoneA”,”ZoneB”,”ZoneC”]
df1=pd.DataFrame(d1,index=index,columns=[“Target”,”S
ales”)
Output:
Solution17:
Import pandas as pd
df1=df1.rename
(index={“zoneB”:”Central”,”zoneC”:”Dakshin”})
df1=df1.rename(columns={“Sales”:”Achieved”})
print(df1)
#Output:
Solution18:
Import pandas as pd
Df1[“Targeted”]=[60000,75000,76000]
Df1[“Achieved”]=[56000,69000,79000]
Print(Df1)
#Output:
Solution19:
Zone_c_data=df1.loc[“zoneC”]
Print(Zone_c_data)
#Output:
Solution20:
Import pandas as pd
Data={‘Name’:[‘Alice’,’Bob’,’Charlie’,’David’,’Eve’],
‘Age’:[25,32,18,47,31], ‘Gender’:[‘Female’,’Male’,’Male’,
‘Male’,’Female’]}
df= pd.DataFrame(Data)
bi1=df[‘Age’] >30
bi2=df[‘Gender’]==’Female’
filtered_df=df(bi1 &bi2)
print(filtered_df)
Output:
Solution1:
Output:
Solution2:
Output:
Solution3:
Output:
Solution4:
Output:
My Sql Queries:
1.Write a Sql command to create a DataBase named
‘School’.
2.Create a student table with the student id, name, and
marks as attributes where the student id is primary key.
3.Add columns ‘Mobile’ and ‘Sex’ in the table student.
4.Add column’Address’ in the table student.
5.Change the name of column ‘Sex’ to ‘Gender’.
6.Delete a column ‘Address’ from table Student.
7.Insert the details of 10 new students in the above
table.
8.Use the select command to get the details of the
students with marks more than 80.
9.Change the mobile number of any one student.
10.Display the details of those students which name start
with’A’.
11.Write output:Select Length(Name),Substr(Name,3,3)
From Student;
12.Write output:Select Count(DistrictGender) From
Student;
13.Display a report like’Aditya’ is scored 20 out 30’ for
each student. Where aditya is the name of student and
20 is the marks of aditya.
14.Find the min,max and average of the marks in a
student marks table.
15.Display the Gender,Minimum marks and Maximum
marks Gender wise.
16.Find the total number of students from student table
gender by using group by.5 Python MySql.
17.Write a Sql query to order the(student Id,marks) table
in descending order.
18.Delete the details of a student in the above table.
19.Delete the table Student.
20.Delete the DataBase School.
Solution of My Sql:
Solution1:
Solution2:
Solution3:
Solution4:
Solution5:
Solution6:
Solution7:
Solution8:
Solution9:
Solution10:
Solution11:
Solution12:
Solution13
Solution14:
Solution15:
Solution16:
Solution17:
Solution18:
Solution19:
Section20: