File size: 3,477 Bytes
0048423
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import pandas as pd
import numpy as np
import plotly.express as px
import streamlit as st


st.set_page_config(
    page_title='Oil Production data Analysis',
    page_icon='📈',
    layout='wide'
)

Years=['1965','1966','1967','1968','1969','1970','1971','1972','1973','1974','1975','1976','1977','1978',
'1979','1980','1981','1982','1983','1984','1985','1986','1987','1988','1989','1990','1991','1992','1993',
'1994','1995','1996','1997','1998','1999','2000','2001','2002','2003','2004','2005','2006','2007','2008',
'2009','2010','2011','2012','2013','2014','2015','2016']

@st.cache_data 
def load_data():
    df=pd.read_csv('data/oil_production_per_person.csv')
    df.rename(columns={'geo':'Country'},inplace=True)
    df.set_index('Country',inplace=True)
    df['Total'] = df[Years].sum(axis=1)
    df['Avgrage']=df.mean(axis=1)
    df['Maximum']=df.max(axis=1)
    df['Minimum']=df.min(axis=1)
    df.sort_index(inplace=True)
    return df

st.title('Oil Production per Person')
df = load_data()
st.dataframe(df,use_container_width=True)

countries= df.index.unique().tolist()
Graphs = ['bar','pie','line','area','funnel']
c1,c2 = st.columns(2)
country = c1.selectbox("Select a Country", countries)
Graph = c2.selectbox("Select a Graph type", Graphs)

st.header("Country wise visualization")
cdf = df.loc[country,Years].reset_index()
cdf.rename({'index':'Years'},axis=1, inplace=True)
if Graph == Graphs[0]:
    fig = px.bar(cdf, 'Years',country, title=f'{country} Oil Production per Person')
if Graph == Graphs[1]:
    fig = px.pie(cdf, 'Years',country, title=f'{country} Oil Production per Person')
if Graph == Graphs[2]:
    fig = px.line(cdf, 'Years',country, title=f'{country} Oil Production per Person')
if Graph == Graphs[3]:
    fig = px.area(cdf, 'Years',country, title=f'{country} Oil Production per Person')
if Graph == Graphs[4]:
    fig = px.funnel(cdf, 'Years',country, title=f'{country} Oil Production per Person')
st.plotly_chart(fig, use_container_width=True)

st.header("Comparison of Countries")
clist = st.multiselect("Select countries to compare", countries, default='India')
cdf = df.loc[clist, Years].T # T to rotate the data in 90deg
st.write(cdf)
figc = px.line(cdf,cdf.index, clist, title=f'Comparing {", ".join(clist)}')

st.plotly_chart(figc, use_container_width=True)

df.sort_values(by='Total', ascending=False, inplace=True)
fig1=px.bar(df, x=df.index, y='Total',title='Total Oil Production per Person')
st.plotly_chart(fig1, use_container_width=True)

dfavg = df.sort_values(by='Avgrage').reset_index()
dfavg.rename({'index':'Country'},axis=1,inplace=True)
fig2=px.bar(dfavg, 'Country', 'Avgrage', title="Avgrage Oil Production by Country")
st.plotly_chart(fig2, use_container_width=True)

dfmax=df.sort_values(by='Maximum').reset_index()
dfmax.rename({'index':'Country'},axis=1,inplace=True)
fig3=px.bar(dfmax,'Country','Maximum',title='Maximum Oil Production by the Country')
st.plotly_chart(fig3, use_container_width=True)

dfmin=df.sort_values(by='Minimum').reset_index()
dfmin.rename({'index':'Country'},axis=1,inplace=True)
fig4=px.bar(dfmin,'Country','Minimum',title='Minimum Oil Production by the Country' )
st.plotly_chart(fig4,use_container_width=True)

dfcomp=df.sort_values(by='Country',ascending=False,inplace=True)
fig5 = px.line(df, x=df.index, y='Maximum',title='Maximum and Minimum Oil Production comparisons')
fig5.add_scatter(x=df.index, y=df['Minimum'], mode='lines',)
st.plotly_chart(fig5, use_container_width=True)