Assignment1_param - converted
Assignment1_param - converted
ASSIGNMENT-1
importing required libraries
In [1]: import pandas as pd
import matplotlib.pyplot as plt
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 6454 entries, 0 to 6453
Data columns (total 5 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 year 6454 non-null int64
1 state 6454 non-null object
2 month 6454 non-null object
3 number 6454 non-null float64
4 date 6454 non-null object
dtypes: float64(1), int64(1), object(3)
memory usage: 252.2+ KB
In [8]: duplicate=df[df.duplicated()]
duplicate
In [9]: df=df.drop_duplicates()
In [10]: df
Out[11]: year 0
state 0
month 0
number 0
date 0
dtype: int64
In [14]: month_map={'Janeiro':'January','Fevereiro':'February','Março':'March','Abril':'A
'Agosto':'August', 'Setembro':'September', 'Outubro':'October', 'Novembro
In [15]: df['month']=df['month'].map(month_map)
df['month'].unique()
In [18]: no_of_cases=df.groupby('month')['number'].sum().sort_values(ascending=False).ind
print(no_of_cases[0],' is the month with highest no. of cases')
In [25]: df3=df[df['state']=='Amazonas'].groupby('year')['number'].sum()
df3
Out[25]: year
1998 946.000
1999 1061.000
2000 853.000
2001 1297.000
2002 2852.000
2003 1524.268
2004 2298.207
2005 1657.128
2006 997.640
2007 589.601
2008 2717.000
2009 1320.601
2010 2324.508
2011 1652.538
2012 1110.641
2013 905.217
2014 2385.909
2015 1189.994
2016 2060.972
2017 906.905
Name: number, dtype: float64
C:\Users\PARAM\AppData\Local\Temp\ipykernel_8680\3119725923.py:2: SettingWithCopy
Warning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
In [30]: df3
Out[30]: date
Sunday 1886.601
Monday 6474.217
Tuesday 3910.177
Wednesday 5754.802
Thursday 5446.480
Friday 4162.666
Saturday 3015.186
Name: number, dtype: float64
In [32]: df2
0 April 2573.000
1 August 4363.125
2 December 4088.522
3 February 2309.000
4 January 4635.000
5 July 4364.392
6 June 3260.552
7 March 2202.000
8 May 2384.000
9 November 4034.518
10 October 4499.525
11 September 2494.658
4 Bahia 187.222703
15 Piau 158.174674
8 Goias 157.721841
22 Tocantins 141.037176
3 Amazonas 128.243218
5 Ceara 127.314071
12 Paraiba 111.073979
9 Maranhao 105.142808
13 Pará 102.561272
14 Pernambuco 102.502092
18 Roraima 102.029598
2 Amapa 91.345506
17 Rondonia 84.876272
0 Acre 77.255356
16 Rio 64.698515
1 Alagoas 19.271967
21 Sergipe 13.543933
In [36]: states=df[df['month']=='December']['state'].unique()
List of states:
Acre
Alagoas
Amapa
Amazonas
Bahia
Ceara
Distrito Federal
Espirito Santo
Goias
Maranhao
Mato Grosso
Minas Gerais
Pará
Paraiba
Pernambuco
Piau
Rio
Rondonia
Roraima
Santa Catarina
Sao Paulo
Sergipe
Tocantins