import seaborn as sns
import pandas as pd
import matplotlib as plt
df = pd.read_csv(r"C:\Users\Anjan\Downloads\elections.csv")
df.head()
| st_name | year | ac_no | ac_name | ac_type | cand_name | cand_sex | partyname | partyabbre | totvotpoll | electors | |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | Andhra Pradesh | 1978.0 | 1 | Ichapuram | GEN | Manabala Ramarao | M | Independent | IND | 813.0 | 83247 |
| 1 | Andhra Pradesh | 1978.0 | 1 | Ichapuram | GEN | Appadu Sahu | M | Independent | IND | 1743.0 | 83247 |
| 2 | Andhra Pradesh | 1978.0 | 1 | Ichapuram | GEN | Uppada Rangababu | M | Indian National Congress | INC | 4427.0 | 83247 |
| 3 | Andhra Pradesh | 1978.0 | 1 | Ichapuram | GEN | Kalla Balarama Swamy | M | Indian National Congress (I) | INC(I) | 19805.0 | 83247 |
| 4 | Andhra Pradesh | 1978.0 | 1 | Ichapuram | GEN | Bendalam Venkatesam Sarma | M | Janata Party | JNP | 34251.0 | 83247 |
df['st_name'].unique().__len__()
30
years = df['year'].unique()
years.sort()
print(years)
[1977. 1978. 1979. 1980. 1982. 1983. 1984. 1985. 1987. 1989. 1990. 1991. 1992. 1993. 1994. 1995. 1996. 1997. 1998. 1999. 2000. 2001. 2002. 2003. 2004. 2005. 2005.1 2006. 2007. 2008. 2009. 2010. 2011. 2012. 2013. 2014. 2015. ]
temp = df[df['st_name'] == 'Bihar']
sns.lineplot(data=temp, x='year', y='electors')
<AxesSubplot:xlabel='year', ylabel='electors'>
temp = df[df['st_name'] == 'Uttar Pradesh']
temp = temp[temp['year'] == 2012.0]
temp.head()
| st_name | year | ac_no | ac_name | ac_type | cand_name | cand_sex | partyname | partyabbre | totvotpoll | electors | |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 305548 | Uttar Pradesh | 2012.0 | 1 | Behat | GEN | Mahmood | M | LD | LD | 565.0 | 303273 |
| 305549 | Uttar Pradesh | 2012.0 | 1 | Behat | GEN | Irshad Urf Bhoora | M | RLM | RLM | 593.0 | 303273 |
| 305550 | Uttar Pradesh | 2012.0 | 1 | Behat | GEN | Vikram | M | VAJP | VAJP | 702.0 | 303273 |
| 305551 | Uttar Pradesh | 2012.0 | 1 | Behat | GEN | Abdul Jabbar | M | NCP | NCP | 726.0 | 303273 |
| 305552 | Uttar Pradesh | 2012.0 | 1 | Behat | GEN | Yashpal | M | ABHM | ABHM | 781.0 | 303273 |
ac_no = temp['ac_no'].unique()
temp1 = temp[temp['ac_name'] == 'Ghazipur']
temp1.__len__()
16
sns.barplot(data=temp1, x='partyname', y='totvotpoll')
<AxesSubplot:xlabel='partyname', ylabel='totvotpoll'>
temp1 = df[df['ac_name'] == 'Lucknow East']
temp1 = temp1[temp1['ac_type'] == 'SC']
# sns.lineplot(data=temp1, x='')
temp1.head()
| st_name | year | ac_no | ac_name | ac_type | cand_name | cand_sex | partyname | partyabbre | totvotpoll | electors | |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 308360 | Uttar Pradesh | 2012.0 | 173 | Lucknow East | GEN | Juhie Singh | F | SP | SP | 47908.0 | 356340 |
ac_types = df['ac_type'].unique()
sns.countplot(data=df, x='ac_type')
# total over period of 1979 to 2015
<AxesSubplot:xlabel='ac_type', ylabel='count'>