Arpit
Arpit
Arpit
INFORMATICS
PRACTICES
(python pandas data frame with CSV)
ROLL NO: 3
CONTENTS
1
1. ACKNOWLEDGEMENT
2. INTRODUCTION
ANALYSIS
6. BASIC MODULES
7. CODES
8. OUTPUTS
9. DATA VISUALISATION
10.CONCLUSION
11.BIBLIOGRAPHY
2
INTRODUCTION
3
ABOUT PYTHON PANDAS
4
the term “panel data”, an econometrics term
for data sets that includes observations over
multiple time periods for the same individuals.
5
quotation marks to surround the field.
Quotation does not solve everything: some
fields may need embedded quotation
marks, so a CSV implementation may
include escape characters or escape
sequences.
OBJECTIVE OF THE
PROJECT
6
for those who cannot afford enough time
to get their tickets reserved by standing
in long queues. People can book tickets at
any time day or night. We also have an
option to cancel the tickets which are
reserved previously.
BASIC MODULES
• Create( ):It is a function used to enter the data
containing details.
7
However, if the .csv file does not have any pre-
existing headers, Pandas can skip this step and
instead start reading the first row of the .csv as
data entries into the data frame.
CODES
8
import pandas as pd
import os
import matplotlib.pyplot as plt
d={'tno':['A1','B2','C3'],
'tname':['Marakkar','No Time To Die','Minnal Murali'],
'tprice':[100,200,300],
'screen':[1,2,1],
'genre':['Thriller','Action','Sci-Fiction']}
df=pd.DataFrame(d)
print('Ticket Information :')
print(df)
df.to_csv('tinfo.csv')
df=pd.read_csv('tinfo.csv')
print(df)
print('Menus available:')
print('1.Add a new row:')
print('2.search a row:' )
print('3.update a row:')
print('4.Delete a row:')
print('5.Table without header:')
print('6.Table without index:')
print('7.Read the CSV file with new column names:')
print('8.Access the values using head()function:')
print('9.Access the values using tail()function:')
print('10.Sorting in ascending order:')
9
print('11.Sorting in descending order:')
print('12.To display of Movie Ticket where price is greater than
100:')
print('13.Changing the existing values into nan:')
print('14.Delete values using index:')
print('Data Visualisation:')
print('15.Bar Graph:')
print('16.Line Graph:')
print('17.Histogram:')
c='y'
while c=='y':
ch=eval(input('Enter your choice:'))
if ch==1:
t=(input('Enter ticket no:'))
tn=input('Enter the ticket name:')
p=int(input('Enter the price:'))
sc=int(input('Enter the screen:'))
g=input('Enter the genre:')
data={'tno':t, 'tname':tn, 'tprice':p, 'screen':sc, 'genre':g}
df=df.append(data,ignore_index=True)
df.to_csv('tinfo.csv')
print(df)
elif ch==2:
n=input('Enter the ticketno:')
df=pd.read_csv('tinfo.csv')
s=df[df['tno']==n]
print(s)
elif ch==3:
N=input('Enter the ticket no:')
df=pd.read_csv('tinfo.csv')
x=df[df['tno']==N].index
Pr=int(input('Enter the new price:'))
df.at[x,'tprice']=Pr
df.to_csv('temp.csv', index=True)
os.remove('tinfo.csv')
os.rename('temp.csv', 'tinfo.csv')
print(df)
elif ch==4:
D=pd.read_csv('tinfo.csv')
bk=D.tname.to_list()
print(bk)
a=input('Enter the tname you want to delete:')
10
if a in bk:
d1=D.drop(df[df.tname==a].index)
d1.to_csv('temp.csv',index=False)
os.remove('tinfo.csv')
os.rename('temp.csv', 'tinfo.csv')
print(d1)
else:
print('Not')
elif ch==5:
df=pd.read_csv('tinfo.csv', header=None)
print('Table without header:')
print(df)
elif ch==6:
df=pd.read_csv('tinfo.csv', index_col=0)
print('Table without index:')
print(df)
elif ch==7:
l=[]
for i in range(5):
nn=input('Enter the new column names:')
l.append(nn)
df=pd.read_csv('tinfo.csv', skiprows=1,names=l)
print('Table with new column names:')
print(df)
elif ch==8:
n=eval(input('No:of values to be selected:'))
print('The first',n,'values are:' )
print(df.head(n))
elif ch==9:
n=eval(input('No:of values to be selected:'))
print('The last',n,'values are:')
print(df.tail(n))
elif ch==10:
cn=input('Enter the column name:')
print('The table sorted in ascending order of',cn,':')
print(df.sort_values(by=[cn]))
elif ch==11:
cn=input('Enter the column name:')
print('The table sorted in descending order of', cn,':')
print(df.sort_values(by=[cn],ascending =False))
elif ch==12:
df=pd.read_csv('tinfo.csv')
11
df1=df.loc[df['tprice']>100]
print(df1)
elif ch==13:
n=eval(input('Enter the no:of values to be changed to nan:')
)
l=[]
for i in range(n):
val=int(input('Enter the values to be changed:'))
l.append(val)
df=pd.read_csv('tinfo.csv',na_values=l)
print(df)
elif ch==14:
n=eval(input('Enter the no:of indices to be removed:'))
l=[]
for i in range(n):
val=int(input('Enter the index to be removed :'))
l.append(val)
print('Values after removed:')
print(df.drop(l))
elif ch==15:
x=['Marakkar','No Time To Die','Minnal Murali']
y=[100,200,300]
plt.bar(x,y,color='b')
plt.xlabel('Movie')
plt.ylabel('price')
plt.title('Bar Graph')
plt.show()
elif ch==16:
x=['Marakkar','No Time To Die','Minnal Murali']
y=[100,200,300]
plt.xlabel('Movie')
plt.ylabel('price')
plt.plot(x,y,'*r',linestyle='dotted')
plt.title('Line Chart')
plt.show()
elif ch==17:
x=['Marakkar','No Time To Die','Minnal Murali']
y=[100,200,300]
plt.hist(x,bins=7,color='red')
plt.xlabel('price')
plt.ylabel('bins')
plt.title('Histogram')
12
plt.show()
else:
print('invalid input')
c=input('Do you want to continue(y/n:’)
OUTPUT
13
Ticket Information :
tno tname tprice screen genre
0 A1 Marakkar 100 1 Thriller
1 B2 No Time To Die 200 2 Action
2 C3 Minnal Murali 300 1 Sci-Fiction
Unnamed: 0 tno tname tprice screen genre
0 0 A1 Marakkar 100 1 Thriller
1 1 B2 No Time To Die 200 2 Action
2 2 C3 Minnal Murali 300 1 Sci-Fiction
Menus available:
1.Add a new row:
2.search a row:
3.update a row:
4.Delete a row:
5.Table without header:
6.Table without index:
7.Read the CSV file with new column names:
8.Access the values using head()function:
9.Access the values using tail()function:
14
10.Sorting in ascending order:
11.Sorting in descending order:
12.To display of Movie Ticket where price is greater than 100:
13.Changing the existing values into nan:
Enter your choice:1
Enter ticket no:D4
Enter the ticket name:Shershaah
Enter the price:400
Enter the screen:2
Enter the genre:Drama
Unnamed: 0 tno tname tprice screen genre
0 0.0 A1 Marakkar 100 1 Romance
15
1 1.0 B2 No time to Die 200 2 Thriller
2 2.0 C3 Minnal Murali 300 1 Action
3 NaN D4 Shershaah 400 2 Drama
2
Enter your choice:2
Enter the ticketno:C3
Unnamed: 0 Unnamed: 0.1 tno tname tprice screen genre
2 2 2.0 C3 Minnal Murali 300 1 Action
Do you want to continue (y/n):
3
16
Enter your choice:3
Enter the ticket no:D4
Enter the new price:450
Unnamed: 0 Unnamed: 0.1 tno tname tprice screen genre
0 0 0.0 A1 Marakkar 100 1 Romance
1 1 1.0 B2 No time to Die 200 2 Thriller
2 2 2.0 C3 Minnal Murali 300 1 Action
3 3 NaN D4 Shershaah 450 2 Drama
Do you want to continue (y/n):
4
Enter your choice:4
17
['Marakkar', 'No time to Die', 'Minnal Murali']
Enter the tname you want to delete:Marakkar
Unnamed: 0 Unnamed: 0.1 Unnamed: 0.1.1 ...
tprice screen genre
1 1 1 1.0 ... 200 2 Thriller
2 2 2 2.0 ... 300 1 Action
[2 rows x 8 columns]
Do you want to continue (y/n)
5
Enter your choice:5
Table without header:
•012345
18
6
Enter your choice:6
Table without index:
tno tname tprice screen genre
0 A1 Marakkar 100 1 Romance
1 B2 No time to Die 200 2 Thriller
2 C3 Minnal Murali 300 1 Action
Do you want to continue (y/n):
Enter your choice:7
Enter the new column names:1
Table with new column names:
1
0 A1 Marakkar 100 1 Romance
1 B2 No time to Die 200 2 Thriller
2 C3 Minnal Murali 300 1 Action
Enter your choice:8
19
No:of values to be selected:2
The first 2 values are:
Unnamed: 0 tno tname tprice screen genre
0 0 A1 Marakkar 100 1 Romance
1 1 B2 No time to Die 200 2 Thriller
Do you want to continue (y/n):
Enter your choice:9
No:of values to be selected:3
The last 3 values are:
Unnamed: 0 tno tname tprice screen genre
0 0 A1 Marakkar 100 1 Romance
1 1 B2 No time to Die 200 2 Thriller
2 2 C3 Minnal Murali 300 1 Action
Do you want to continue (y/n):
Enter your choice:10
Enter the column name:tno
The table sorted in ascending order of tno :
Unnamed: 0 tno tname tprice screen genre
20
0 0 A1 Marakkar 100 1 Romance
1 1 B2 No time to Die 200 2 Thriller
2 2 C3 Minnal Murali 300 1 Action
Do you want to continue (y/n):
Enter your choice:11
Enter the column name:tno
The table sorted in descending order of tno :
Unnamed: 0 tno tname tprice screen genre
2 2 C3 Minnal Murali 300 1 Action
1 1 B2 No time to Die 200 2 Thriller
0 0 A1 Marakkar 100 1 Romance
Do you want to continue (y/n):
Enter your choice:12
Unnamed: 0 tno tname tprice screen genre
1 1 B2 No time to Die 200 2 Thriller
21
2 2 C3 Minnal Murali 300 1 Action
Do you want to continue (y/n):
Enter your choice:13
Enter the no:of values to be changed to nan:2
Enter the values to be changed:100
Unnamed: 0 tno tname tprice screen genre
0 0 A1 Marakkar NaN 1 Romance
1 1 B2 No time to Die 200.0 2 Thriller
2 2 C3 Minnal Murali 300.0 1 Action
Enter the values to be changed:
Enter your choice:14
Enter the no:of indices to be removed:1
Enter the index to be removed :1
Values after removed:
Unnamed: 0 tno tname tprice screen genre
0 0 A1 Marakkar 100 1 Romance
2 2 C3 Minnal Murali 300 1 Action
DATA VISUALISATION
22
We all Know that images or visuals are
we sure are powerful for most
communication . We often use them to
understand a situation better or to
condense pieces of information into a
graphical representation.
23
BAR GRAPH:-
LINE CHART:-
HISTOGRAM:-
24
OUTPUT
25
26
27
CONCLUSION
28
BIBLIOGRAPHY
https://www.python.org/
https://www.learnpython.org/
https://www.research,org/
29
1