-
Notifications
You must be signed in to change notification settings - Fork 15
/
Data plots.py
48 lines (37 loc) · 1.36 KB
/
Data plots.py
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
# -*- coding: utf-8 -*-
"""
Created on Wed Nov 11 18:41:59 2020
@author: user
"""
import pandas as pd
import matplotlib.pyplot as plt
###############################################################################
datainput = pd.read_csv("datafile.csv", delimiter = ',')
####################################################################
#Plot 1. Crops in percentage
Crops = datainput.iloc[:,0]
CropsCount = {}
for crop in Crops:
CropsCount[crop] = CropsCount.get(crop, 0)+1
#extract values and keys of dict:CropsCount
labels = list(CropsCount.keys())
values = list(CropsCount.values())
plt.pie(values, labels=labels,autopct='%1.1f%%')
plt.show()
####################################################################
#Plot 2. State distribution
States = datainput.iloc[:,1]
StatesCount = {}
for state in States:
StatesCount[state] = StatesCount.get(state, 0)+1
#extract values and keys of dict:CropsCount
labels = list(StatesCount.keys())
values = list(StatesCount.values())
plt.pie(values, labels=labels,autopct='%1.1f%%')
plt.show()
###################################################################
#Plot 3. Yield per Crop
plt.tick_params(labelsize=8)
datainput.groupby("Crop")["Yield (Quintal/ Hectare) "].agg("sum").plot.bar()
###################################################################
#Plot 4.