Brief Overview of Python (1)
Brief Overview of Python (1)
References / Bibliography:
BRIEF OVERVIEW OF PYTHON
WHAT IS PYTHON ?
Python is an programming language with dynamic semantics, it was introduced by
Guido Van Rossum in 1991 . Its high-level built in data structures, combined with
dynamic typing and binding, make it very attractive for Rapid Application
Development, as well as for use as a scripting language. Python's simple, easy to learn
syntax emphasizes readability and therefore reduces the cost of program
maintenance. Python supports modules and packages, which encourages program
modularity and code reuse. The Python interpreter is available in source or binary form
without charge for all major platforms.
USES OF PYTHON
Python is commonly used for developing websites and software, task
automation, data analysis, and data visualization. Since it’s relatively easy to
learn, Python has been adopted by many non-programmers, such as
accountants and scientists, for a variety of everyday tasks, like organizing
finances.
USES OF PANDAS
Pandas allows us to analyze big data and make conclusions based on statistical
theories.Pandas can clean messy data sets, and make them readable and
relevant. Relevant data is very important in data science
Matplotlib
What is Matplotlib ?
Matplotlib is a popular data visualization library in Python.It is a
comprehensive library for creating static, animated, and interactive
visualizations in Python. Matplotlib makes easy things easy and hard things
possible. Create publication quality plots. Make interactive figures that can
zoom, pan, update. Customize visual style and layout.
USES OF MATPLOTLIB
It's often used for creating static,
interactive, and animated visualizations in
Python. Matplotlib allows you to generate
plots, histograms, bar charts, scatter plots,
etc., with just a few lines of code.
DATABASE
A database is a file that is organized for storing data. Most databases are
organized like a dictionary in the sense that they map from keys to values.
The biggest difference is that the database is on disk (or other permanent
storage), so it persists after the program ends.
frame .
CODING
import pandas as pd
import matplotlib.pyplot as plt
import sys
def Analysis():
df = pd.read_csv('/content/Untitled spreadsheet - Sheet1.csv')
while True:
print('Data Frame Analysis')
print('*')
menu = '''
1. Top records
2. Bottom records
3. Display literacy rates of a particular state
4. Display states with literacy rate >= n%
5. State with maximum literacy rate
6. Average literacy rate of India
7. Display complete dataframe
8. Back to menu
'''
print(menu)
print('')
if ch_an == 1:
n = int(input('Enter the number of records to be displayed: '))
print('Top', n, 'records from the dataframe:')
print(df.head(n))
elif ch_an == 2:
n = int(input('Enter the number of records to be displayed: '))
print('Bottom', n, 'records from the dataframe:')
print(df.tail(n))
elif ch_an == 3:
print('Name of columns:', df.columns)
col = input('Enter the state of choice: ')
if col in df['States & UTs'].values:
state_data = df[df['States & UTs'] == col]
print(f"{col} Average\nLiteracy Rate %:", state_data['Average\nLiteracy
Rate %'].values[0])
else:
print("State not found in the DataFrame.")
elif ch_an == 4:
m = float(input('Enter percentage: '))
states = df[df['Average\nLiteracy Rate %'] >= m]
print(f'States and UTs with literacy rate >= {m}%:')
print(states[['States & UTs', 'Average\nLiteracy Rate %']])
elif ch_an == 5:
max_rate_row = df.loc[df['Average\nLiteracy Rate %'].idxmax()]
print('State with highest literacy rate:', max_rate_row['States & UTs'], 'with a
rate of', max_rate_row['Average\nLiteracy Rate %'])
elif ch_an == 6:
avg_rate = df['Average\nLiteracy Rate %'].mean()
print('Average literacy rate of India:', avg_rate)
elif ch_an == 7:
print('Displaying Dataframe:')
print(df)
print('')
elif ch_an == 8:
break
def Visuals():
df=pd.read_csv('/content/Untitled spreadsheet - Sheet1.csv')
while True:
print('VISUAL MENU')
print('==================================')
print('1-Line chart for particular states on basis of avg. literacy rate')
print('2-Bar graph state wise male and female literacy rate')
print('3-Line chart on the basis for particular states on the basis of male female and
avg. literacy rate')
print('4-Bar for particular states on the basis of male female and avg. literacy rate')
print('5-Back to main menu')
print('***********************************************************************************************
*************')
choice=int(input('Enter choice-'))
if choice==1:
n=int(input('Enter num of states(1-36)-'))
df0=df.head(n)
print(df0)
df0.plot(kind='line',x='States & UTs',y='Average\nLiteracy Rate %')
plt.show()
elif choice==2:
n=int(input('Enter num of states(1-36)-'))
df2=df.head(n)
print(df2)
df2.plot(kind='bar',x='States & UTs')
plt.show()
elif choice==3:
n=int(input('Enter num of states(1-36)-'))
df1=df.head(n)
print(df1)
df1.plot(kind='line',x='States & UTs')
plt.show()
elif choice==4:
df3=df
df3=df3.drop('Average\nLiteracy Rate %',axis=1)
print(df3)
n=int(input('Enter num of states(1-36)-'))
df4=df3.head(n)
print(df4)
df4.plot(kind='bar',x='States & UTs')
plt.show()
else:
Break
for n in range (0,1):
print('****************************************')
print('_______________________________________________')
print('1-Analysis\n')
print('2-Data Visualisation\n')
print('3-Manipulation\n')
print('4-Exit')
print('.............................................................................')
if opt=='1':
Analysis()
elif opt=='2':
Visuals()
elif opt=='3':
Manipulation()
else:
my_chance=input('Type y to exit.')
if my_chance=='y'or my_chance=='Y':
sys.exit()
else:
OUTPUT
****************************************
LITERACY RATE OF INDIA
_______________________________________________
1-Analysis
2-Data Visualisation
3-Manipulation
4-Exit
.............................................................................
Enter Your Choice:1
<ipython-input-92-07433ca93c33>:5: UserWarning: Pandas doesn't allow columns
to be created via a new attribute name - see
https://pandas.pydata.org/pandas-docs/stable/indexing.html#attribute-access
df.colums = df.columns.str.replace('\n', ' ')
Data Frame Analysis
*
1. Top records
2. Bottom records
3. Display literacy rates of a particular state
4. Display states with literacy rate >= n%
5. State with maximum literacy rate
6. Average literacy rate of India
7. Display complete dataframe
8. Back to menu
Average\nLiteracy Rate %
0 86.27
1 66.40
2 66.95
3 85.90
4 70.90
5 77.30
6 86.43
7 77.65
8 87.07
9 88.70
Data Frame Analysis
*
1. Top records
2. Bottom records
3. Display literacy rates of a particular state
4. Display states with literacy rate >= n%
5. State with maximum literacy rate
6. Average literacy rate of India
7. Display complete dataframe
8. Back to menu
Average\nLiteracy Rate %
27 83.70
28 69.70
29 82.20
30 82.90
31 72.80
32 87.75
33 87.60
34 73.00
35 80.50
36 77.70
Data Frame Analysis
*
1. Top records
2. Bottom records
3. Display literacy rates of a particular state
4. Display states with literacy rate >= n%
5. State with maximum literacy rate
6. Average literacy rate of India
7. Display complete dataframe
8. Back to menu
1. Top records
2. Bottom records
3. Display literacy rates of a particular state
4. Display states with literacy rate >= n%
5. State with maximum literacy rate
6. Average literacy rate of India
7. Display complete dataframe
8. Back to menu
Data Frame Analysis
1. Top records
2. Bottom records
3. Display literacy rates of a particular state
4. Display states with literacy rate >= n%
5. State with maximum literacy rate
6. Average literacy rate of India
7. Display complete dataframe
8. Back to menu
1. Top records
2. Bottom records
3. Display literacy rates of a particular state
4. Display states with literacy rate >= n%
5. State with maximum literacy rate
6. Average literacy rate of India
7. Display complete dataframe
8. Back to menu
1. Top records
2. Bottom records
3. Display literacy rates of a particular state
4. Display states with literacy rate >= n%
5. State with maximum literacy rate
6. Average literacy rate of India
7. Display complete dataframe
8. Back to menu
Average\nLiteracy Rate %
0 86.27
1 66.40
2 66.95
3 85.90
4 70.90
5 77.30
6 86.43
7 77.65
8 87.07
9 88.70
10 87.40
11 82.40
12 80.40
13 86.60
14 77.30
15 74.30
16 77.20
17 96.20
18 92.28
19 73.70
20 84.80
21 79.85
22 75.48
23 91.58
24 80.11
25 77.30
26 86.55
27 83.70
28 69.70
29 82.20
30 82.90
31 72.80
32 87.75
33 87.60
34 73.00
35 80.50
36 77.70
1. Top records
2. Bottom records
3. Display literacy rates of a particular state
4. Display states with literacy rate >= n%
5. State with maximum literacy rate
6. Average literacy rate of India
7. Display complete dataframe
8. Back to menu
_______________________________________________
1-Analysis
2-Data Visualisation
3-Manipulation
4-Exit
.............................................................................
VISUAL MENU
==================================
3-Line chart on the basis for particular states on the basis of male female and avg. literacy rate
4-Bar for particular states o the basis of male female and avg. literacy rate
************************************************************************************************************
Enter choice-1
Average\nLiteracy Rate %
0 86.27
1 66.40
2 66.95
3 85.90
4 70.90
5 77.30
6 86.43
7 77.65
8 87.07
9 88.70
VISUAL MENU
==================================
3-Line chart on the basis for particular states on the basis of male female and avg. literacy rate
4-Bar for particular states o the basis of male female and avg. literacy rate
************************************************************************************************************
Enter choice-2
Average\nLiteracy Rate %
0 86.27
1 66.40
2 66.95
3 85.90
4 70.90
5 77.30
6 86.43
7 77.65
8 87.07
9 88.70
VISUAL MENU
==================================
1-Line chart for particular states on basis od avg. literacy rate
2-Bar graph state wise male and female literacy rate
3-Line chart on the basis for particular states on the basis of male female and avg. literacy rate
4-Bar for particular states o the basis of male female and avg. literacy rate
5-Back to main menu
********************************************************************************************************
****
Enter choice-3
Enter num of states(1-36)-3
States & UTs Male\nLiteracy Rate % Female\nLiteracy Rate % \
0 A&N islands 90.11 81.84
1 Andhra Pradesh 73.40 59.50
2 Arunachal Pradesh 73.69 59.57
Average\nLiteracy Rate %
0 86.27
1 66.40
2 66.95
VISUAL MENU
==================================
3-Line chart on the basis for particular states on the basis of male female and avg. literacy rate
4-Bar for particular states o the basis of male female and avg. literacy rate
************************************************************************************************************
Enter choice-3
Average\nLiteracy Rate %
0 86.27
1 66.40
2 66.95
3 85.90
4 70.90
5 77.30
6 86.43
7 77.65
8 87.07
9 88.70
VISUAL MENU
==================================
3-Line chart on the basis for particular states on the basis of male female and avg. literacy rate
4-Bar for particular states o the basis of male female and avg. literacy rate
************************************************************************************************************
Enter choice-3
Average\nLiteracy Rate %
0 86.27
1 66.40
2 66.95
3 85.90
4 70.90
5 77.30
6 86.43
7 77.65
8 87.07
9 88.70
10 87.40
11 82.40
12 80.40
13 86.60
14 77.30
15 74.30
16 77.20
17 96.20
18 92.28
19 73.70
20 84.80
21 79.85
22 75.48
23 91.58
24 80.11
25 77.30
26 86.55
27 83.70
28 69.70
29 82.20
30 82.90
31 72.80
32 87.75
33 87.60
34 73.00
35 80.50
VISUAL MENU
==================================
3-Line chart on the basis for particular states on the basis of male female and avg. literacy rate
4-Bar for particular states o the basis of male female and avg. literacy rate
************************************************************************************************************
Enter choice-4
==================================
1-Line chart for particular states on the basis of avg. literacy rate
3-Line chart on the basis for particular states on the basis of male female and avg. literacy rate
4-Bar for particular states on the basis of male female and avg. literacy rate
5-Back to main menu
************************************************************************************************************
Enter choice-5