repl.it
@Caoyq1992/

Data Visualization with Python

Python

No description

fork
loading
Files
  • main.py
  • 1.png
  • graph.png
  • iris.csv
  • Packager files
  • poetry.lock
  • pyproject.toml
  • requirements.txt
main.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
49
50
51
52
53
54
55
56
# Load libraries
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
import matplotlib as mpl
import os

# The following section is just for our online class
mpl.use('Agg')
if os.path.exists('1.png'):
 os.remove('1.png')

column_names=['sepal-length','sepal-width','petal-length','petal-width','class']
dataset=pd.read_csv('iris.csv',names=column_names)

# print(dataset.columns)
# print(dataset.head(20))
# print(dataset.iloc[7:20]) # Index location

# print(dataset['class'].unique())
dataset=dataset.dropna(subset=['class'])

dataset['class']=dataset['class'].replace(to_replace={'.*IVC.*':'Iris-versicolor'}, regex=True)

print(dataset['class'].unique())

dataset=dataset[(dataset['class']!='undefined')]
print(dataset['class'].unique())
# print(dataset)

# group_by_class=dataset.groupby(by=['class'])
# class_avg=group_by_class.mean()
# print(class_avg)

# class_data_count=group_by_class.count()
# print(class_data_count)

# Box and whisker plots
# dataset.plot(kind='box',subplots=True,layout=(2,2),sharex=False,sharey=False)

# dataset.plot.box()

# dataset.plot.hist()
# dataset.hist()

from pandas.plotting import scatter_matrix
scatter_matrix(dataset)
plt.show
plt.savefig('1.png')