0% found this document useful (0 votes)
18 views21 pages

Import Pandas As PD

Uploaded by

useexternal57
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)
18 views21 pages

Import Pandas As PD

Uploaded by

useexternal57
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/ 21

TABLE OF CONTENTS

S.NO DESCRIPTION PAGE


NO
1 ACKNOWLEDGEMENT
2 PROJECT LOGBOOK
3 INTRODUCTION
4 OBJECTIVES OF THE PROJECT
5 THEORETICAL BACKGROUND
6 FLOW CHART
7 SOURCE CODE
8 OUTPUT
9 FIGURES
10 CSV FILES
11 HARDSOFTWARE AND
SOFTWARE REQUIREMENT
12 RESOURCES
INTRODUCTION

This programme is an intricate analysis of elections in India. The


program seeks to provide information to the user about the data of
elections in our country and how they affect democracy
It provides an option to the user to select from the options presented
in the MENU related to the various analytic dimensions of election in
India.

● Major 10 State which contribute to Indian economy


● Number of registered parties in a state
● Number of Constituencies in a state
● Name of the parties
● And the candidate that belong to that party and the
● Votes secured by the candidate.

This project is an attempt to make the user aware of the significant


impact of election in India on us as individuals, and as a society, along
with the brief global scenario.
OBJECTIVES OF THE PROJECT

The objective of this project is to let the students apply the


programming knowledge into a real- world situation/problem and
expose the students how programming skills help in developing a
good software.

1. Write programs utilizing modern software tools.

2. Apply object-oriented programming principles effectively when


Developing small to medium sized projects.

3. Write effective procedural code to solve small to medium sized


problems.

4. Students will demonstrate a breadth of knowledge in computer


science, as exemplified in the areas of systems, theory and software
development.

5. Students will demonstrate the ability to conduct research or


applied Computer Science project, requiring writing and presentation
skills which exemplify scholarly style in computer science.
THEORETICAL BACKGROUND

What is python?

Python IS an open source, Object-Oriented-High-Level programming


language
developed by Guido Van Rossum in 1991 at the National Research
Institute for Mathematics, Netherlands.

Features of Python:

● It is an interactive, interpreted language.


● It is a loosely typed object -oriented language.
● It is a free open-source and portable language,
● It takes less time to develop programs.
● It is extensible/extendable and highly efficient.
● It supports GUI.
● It can be easily compatible with other languages like C, C++ etc.
● It is used for both scientific and non-scientific programming.
What is python?

Pandas is a Python library used for working with data sets. It has functions for
analysing, cleaning, exploring, and manipulating data.
The name "Pandas" has a reference to both "Panel Data", and "Python Data
Analysis" and was created by Wes McKinney in 2008.
Pandas allows us to analyse 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.

What is matplotlib?

Matplotlib is a graph plotting library in python that serves as a visualization


utility.
Matplotlib was created by John D. Hunter in 2002 and is an open source library
that can be used freely.
It is a multi-platform data visualization library built on NumPy arrays and
designed to work with the broader SciPy stack. One of the greatest benefits of
visualization is that it allows us visual access to huge amounts of data in easily
digestible visuals.
Matplotlib consists of several plots like line, bar, scatter, histogram, etc.
SOURCE CODE

import pandas as pd
import matplotlib.pyplot as plt
import numpy as np

# File paths
file1 = "C:/Users/santa/OneDrive/Desktop/monish reddy/ip pr 1.csv"
file2 = "C:/Users/santa/OneDrive/Desktop/monish reddy/ip pr2.csv"

# Load datasets
data1 = pd.read_csv(file1) # Load the first dataset containing
information about registered parties
data2 = pd.read_csv(file2) # Load the second dataset containing
votes information

# Ensure VOTES column is numeric


data2['VOTES'] = pd.to_numeric(data2['VOTES'],
errors='coerce').fillna(0) # Convert 'VOTES' to numeric, replacing
non-numeric with 0

# Menu-driven program
while True:
# Display menu options for the user to choose the type of graph
print("\nChoose a graph to generate:")
print("1. Pie chart of Registered Parties")
print("2. Bar chart of Registered Parties by State")
print("3. Bar chart of Votes by Constituency")
print("4. Candlestick chart of Constituencies by State")
print("5. Scatter plot of Votes vs Constituencies")
print("6. Bar chart of Votes by State")
print("7. Candlestick chart of Votes by State")
print("8. Exit")

choice = input("Enter your choice (1-8): ") # Get user input for the
graph selection

if choice == '1':
# Pie chart of Registered Parties
registered_parties = data1['REGISTERED PARTIES'].value_counts()
# Get the count of each party type
labels = registered_parties.index # Party labels
values = registered_parties.values # Party counts

# Create pie chart


plt.figure(figsize=(8, 8))
plt.pie(values, labels=labels, autopct='%1.1f%%', startangle=140,
colors=['#ff9999', '#66b3ff', '#99ff99', '#ffcc99'],
wedgeprops={'linewidth': 1.5, 'edgecolor': 'black'})
plt.title("Distribution of Registered Parties", fontsize=16)
plt.tight_layout() # Adjust layout to fit content
plt.show()

elif choice == '2':


# Bar chart of Registered Parties by State
state_party_counts = data1.groupby('STATE')['REGISTERED
PARTIES'].sum() # Sum of registered parties per state

# Create bar chart


plt.figure(figsize=(12, 6))
plt.bar(state_party_counts.index, state_party_counts.values,
color='#66b3ff', edgecolor='black', width=0.6)
plt.title("Number of Registered Parties by State", fontsize=16)
plt.xlabel("State", fontsize=14)
plt.ylabel("Registered Parties", fontsize=14)
plt.xticks(rotation=45, ha='right') # Rotate state labels for
readability
plt.grid(axis='y', linestyle='--', alpha=0.7) # Add gridlines for y-
axis
plt.tight_layout()
plt.show()

elif choice == '3':


# Bar chart of Votes by Constituency
constituency_votes = data2.groupby('CONSITUENCY')
['VOTES'].sum() # Sum of votes per constituency
constituencies = constituency_votes.index # Constituency
names
votes = constituency_votes.values # Vote counts

# Create bar chart


plt.figure(figsize=(12, 6))
plt.bar(constituencies, votes, color='#ff9999', edgecolor='black')
plt.title("Bar Chart: Votes by Constituency", fontsize=16)
plt.xlabel("Constituency", fontsize=14)
plt.ylabel("Votes", fontsize=14)
plt.xticks(rotation=45, fontsize=12) # Rotate constituency labels
for readability
plt.grid(axis='y', linestyle='--', alpha=0.7) # Add gridlines for y-
axis
plt.tight_layout()
plt.show()

elif choice == '4':


# Candlestick chart of Constituencies by State
state_constituencies = data2.groupby('STATE')
['CONSITUENCY'].sum() # Sum of constituencies per state
states = state_constituencies.index # State names
values = state_constituencies.values # Constituency counts
# Create candlestick chart
plt.figure(figsize=(12, 6))
for i, value in enumerate(values):
plt.plot([i, i], [0, value], color='black', linewidth=2) # Draw
vertical line (stick)
plt.scatter(i, value, color='red', s=100, zorder=3) # Draw
marker at the top (candle top)

plt.title('Candlestick Chart: Constituencies by State', fontsize=16)


plt.xlabel('State', fontsize=14)
plt.ylabel('Number of Constituencies', fontsize=14)
plt.xticks(range(len(states)), states, rotation=45, fontsize=12) #
Rotate state labels
plt.grid(axis='y', linestyle='--', alpha=0.7) # Add gridlines for y-
axis
plt.tight_layout()
plt.show()

elif choice == '5':


# Scatter plot of Votes vs Constituencies
plt.figure(figsize=(12, 8))
plt.scatter(data2['CONSITUENCY'], data2['VOTES'], color='purple',
alpha=0.6, edgecolor='black')
plt.title("Scatter Plot: Votes vs Constituencies", fontsize=16)
plt.xlabel("Constituencies", fontsize=14)
plt.ylabel("Votes", fontsize=14)
plt.grid(axis='both', linestyle='--', alpha=0.7) # Add gridlines for
both axes
plt.tight_layout()
plt.show()

elif choice == '6':


# Bar chart of Votes by State
state_votes = data2.groupby('STATE')['VOTES'].sum() # Sum of
votes per state
states = state_votes.index # State names
votes = state_votes.values # Vote counts

# Create bar chart


plt.figure(figsize=(12, 6))
plt.bar(states, votes, color='orange', edgecolor='black')
plt.title("Bar Chart: Votes by State", fontsize=16)
plt.xlabel("State", fontsize=14)
plt.ylabel("Votes", fontsize=14)
plt.xticks(rotation=45, fontsize=12) # Rotate state labels for
readability
plt.grid(axis='y', linestyle='--', alpha=0.7) # Add gridlines for y-
axis
plt.tight_layout()
plt.show()

elif choice == '7':


# Candlestick chart of Votes by State
state_votes = data2.groupby('STATE')['VOTES'].sum() # Sum of
votes per state
states = state_votes.index # State names
values = state_votes.values # Vote counts

# Create candlestick chart


plt.figure(figsize=(12, 6))
for i, value in enumerate(values):
plt.plot([i, i], [0, value], color='black', linewidth=2) # Draw
vertical line (stick)
plt.scatter(i, value, color='blue', s=100, zorder=3) # Draw
marker at the top (candle top)

plt.title('Candlestick Chart: Votes by State', fontsize=16)


plt.xlabel('State', fontsize=14)
plt.ylabel('Votes', fontsize=14)
plt.xticks(range(len(states)), states, rotation=45, fontsize=12) #
Rotate state labels
plt.grid(axis='y', linestyle='--', alpha=0.7) # Add gridlines for y-
axis
plt.tight_layout()
plt.show()

elif choice == '8':


print("Exiting program.") # Exit message
break # Break the loop to exit the program

else:
print("Invalid choice. Please enter a number between 1 and 8.")
# Handle invalid input

OUTPUT
GRAPHS
FIGURE 1
FIGURE 2

FIGURE 3
FIGURE 4

FIGURE 5
FIGURE 6

FIGURE-7
CSV-FILES
CSV-1

CSV-2
RESOURCES

WWW.GOOGLE.COM
WWW.TIMES OF INDIA.COM
WWW.THE HINDU.COM
WWW.GOV IND.COM
WWW.WIKIPEDIA.com

You might also like