0% found this document useful (0 votes)
27 views10 pages

Script TugasStatistika1B Kelompok4

The document shows the installation and usage of Python, Pandas, NumPy, Seaborn and Matplotlib on a Windows system. Various data analysis tasks are performed on a CSV dataset including plotting histograms, calculating descriptive statistics and performing binning.

Uploaded by

AMPamasengi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views10 pages

Script TugasStatistika1B Kelompok4

The document shows the installation and usage of Python, Pandas, NumPy, Seaborn and Matplotlib on a Windows system. Various data analysis tasks are performed on a CSV dataset including plotting histograms, calculating descriptive statistics and performing binning.

Uploaded by

AMPamasengi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

Microsoft Windows [Version 10.0.19042.

1165]

(c) Microsoft Corporation. All rights reserved.

C:\Users\asus>python --version

Python 3.9.7

C:\Users\asus>python -m pip install pandas

Collecting pandas

Downloading pandas-1.3.2-cp39-cp39-win_amd64.whl (10.2 MB)

|████████████████████████████████| 10.2 MB 433 kB/s

Collecting python-dateutil>=2.7.3

Downloading python_dateutil-2.8.2-py2.py3-none-any.whl (247 kB)

|████████████████████████████████| 247 kB 1.6 MB/s

Collecting numpy>=1.17.3

Downloading numpy-1.21.2-cp39-cp39-win_amd64.whl (14.0 MB)

|████████████████████████████████| 14.0 MB 6.8 MB/s

Collecting pytz>=2017.3

Downloading pytz-2021.1-py2.py3-none-any.whl (510 kB)

|████████████████████████████████| 510 kB 939 kB/s

Collecting six>=1.5

Downloading six-1.16.0-py2.py3-none-any.whl (11 kB)

Installing collected packages: six, pytz, python-dateutil, numpy, pandas

Successfully installed numpy-1.21.2 pandas-1.3.2 python-dateutil-2.8.2 pytz-2021.1 six-1.16.0

WARNING: You are using pip version 21.2.3; however, version 21.2.4 is available.

You should consider upgrading via the 'C:\Users\asus\AppData\Local\Programs\Python\Python39\


python.exe -m pip install --upgrade pip' command.

C:\Users\asus>python -m pip install numpy


Requirement already satisfied: numpy in c:\users\asus\appdata\local\programs\python\python39\lib\
site-packages (1.21.2)

WARNING: You are using pip version 21.2.3; however, version 21.2.4 is available.

You should consider upgrading via the 'C:\Users\asus\AppData\Local\Programs\Python\Python39\


python.exe -m pip install --upgrade pip' command.

C:\Users\asus>python -m pip install seaborn

Collecting seaborn

Downloading seaborn-0.11.2-py3-none-any.whl (292 kB)

|████████████████████████████████| 292 kB 327 kB/s

Requirement already satisfied: numpy>=1.15 in c:\users\asus\appdata\local\programs\python\


python39\lib\site-packages (from seaborn) (1.21.2)

Collecting matplotlib>=2.2

Downloading matplotlib-3.4.3-cp39-cp39-win_amd64.whl (7.1 MB)

|████████████████████████████████| 7.1 MB 192 kB/s

Collecting scipy>=1.0

Downloading scipy-1.7.1-cp39-cp39-win_amd64.whl (33.8 MB)

|████████████████████████████████| 33.8 MB 435 kB/s

Requirement already satisfied: pandas>=0.23 in c:\users\asus\appdata\local\programs\python\


python39\lib\site-packages (from seaborn) (1.3.2)

Collecting pillow>=6.2.0

Downloading Pillow-8.3.2-cp39-cp39-win_amd64.whl (3.2 MB)

|████████████████████████████████| 3.2 MB 273 kB/s

Collecting kiwisolver>=1.0.1

Downloading kiwisolver-1.3.2-cp39-cp39-win_amd64.whl (52 kB)

|████████████████████████████████| 52 kB 191 kB/s

Collecting pyparsing>=2.2.1

Downloading pyparsing-2.4.7-py2.py3-none-any.whl (67 kB)

|████████████████████████████████| 67 kB 364 kB/s


Requirement already satisfied: python-dateutil>=2.7 in c:\users\asus\appdata\local\programs\python\
python39\lib\site-packages (from matplotlib>=2.2->seaborn) (2.8.2)

Collecting cycler>=0.10

Downloading cycler-0.10.0-py2.py3-none-any.whl (6.5 kB)

Requirement already satisfied: six in c:\users\asus\appdata\local\programs\python\python39\lib\site-


packages (from cycler>=0.10->matplotlib>=2.2->seaborn) (1.16.0)

Requirement already satisfied: pytz>=2017.3 in c:\users\asus\appdata\local\programs\python\


python39\lib\site-packages (from pandas>=0.23->seaborn) (2021.1)

Installing collected packages: pyparsing, pillow, kiwisolver, cycler, scipy, matplotlib, seaborn

Successfully installed cycler-0.10.0 kiwisolver-1.3.2 matplotlib-3.4.3 pillow-8.3.2 pyparsing-2.4.7 scipy-


1.7.1 seaborn-0.11.2

WARNING: You are using pip version 21.2.3; however, version 21.2.4 is available.

You should consider upgrading via the 'C:\Users\asus\AppData\Local\Programs\Python\Python39\


python.exe -m pip install --upgrade pip' command.

C:\Users\asus>python

Python 3.9.7 (tags/v3.9.7:1016ef3, Aug 30 2021, 20:19:38) [MSC v.1929 64 bit (AMD64)] on win32

Type "help", "copyright", "credits" or "license" for more information.

>>> import pandas as pd

>>> import numpy as np

>>> import seaborn as sns

>>> import matplotlib.pyplot as plt

>>> df=pd.read_csv("Downloads\CJ_SiMg.csv")

>>> df.head(5)

Vol SiO2 MgO

0 Slamet 51.2 0.19

1 Slamet 58.2 0.15

2 Slamet 54.0 0.17

3 Slamet 57.5 0.16

4 Slamet 63.2 0.12


>>> df.tail(5)

Vol SiO2 MgO

665 Bawean 49.0 5.09

666 Bawean 49.0 6.02

667 Bawean 52.8 1.60

668 Bawean 52.6 3.87

669 Bawean 56.0 0.14

>>> df.describe()

SiO2 MgO

count 670.000000 670.000000

mean 54.258760 3.040846

std 3.919386 1.336254

min 44.789050 0.120000

25% 52.100925 2.400000

50% 54.100000 2.830925

75% 55.500000 3.340000

max 75.300000 10.400000

>>> df.median()

<stdin>:1: FutureWarning: Dropping of nuisance columns in DataFrame reductions (with


'numeric_only=None') is deprecated; in a future version this will raise TypeError. Select only valid
columns before calling the reduction.

SiO2 54.100000

MgO 2.830925

dtype: float64

>>> sns.displot(data=df, x="SiO2")

<seaborn.axisgrid.FacetGrid object at 0x0000028EF8520130>

>>> plt.show()

>>> sns.displot(data=df, x="MgO", kde=True)

<seaborn.axisgrid.FacetGrid object at 0x0000028EF84FAC70>


>>> plt.show()

>>> min=df['SiO2'].min()

>>> max=df['SiO2'].max()

>>> print(min)

44.78905

>>> print(max)

75.3

>>> sturgesCI=1+((3.3)*np.log(670))

>>> print(sturgesCI)

22.474016450870536

>>> sns.displot(data=df, x="SiO2", bins=23)

<seaborn.axisgrid.FacetGrid object at 0x0000028E80257040>

>>> plt.show()

>>> sns.displot(data=df, x="SiO2", discrete=True)

<seaborn.axisgrid.FacetGrid object at 0x0000028EFC3CA3A0>

>>> plt.show()

>>> class_int=1+((3.3)*np.log(670))

>>> print(class_int)

22.474016450870536

>>> CI=pd.cut(df['SiO2'], 23)

>>> print(CI)

0 (50.095, 51.422]

1 (58.055, 59.381]

2 (52.748, 54.075]

3 (56.728, 58.055]

4 (62.034, 63.361]

...

665 (48.769, 50.095]

666 (48.769, 50.095]


667 (52.748, 54.075]

668 (51.422, 52.748]

669 (55.402, 56.728]

Name: SiO2, Length: 670, dtype: category

Categories (23, interval[float64, right]): [(44.759, 46.116] < (46.116, 47.442] < (47.442, 48.769] <

(48.769, 50.095] ... (69.994, 71.32] < (71.32, 72.647] <

(72.647, 73.973] < (73.973, 75.3]]

>>> pd.value_counts(CI)

(54.075, 55.402] 161

(52.748, 54.075] 127

(55.402, 56.728] 83

(51.422, 52.748] 81

(50.095, 51.422] 67

(56.728, 58.055] 26

(48.769, 50.095] 25

(60.708, 62.034] 17

(47.442, 48.769] 15

(59.381, 60.708] 12

(58.055, 59.381] 11

(62.034, 63.361] 9

(63.361, 64.687] 9

(44.759, 46.116] 9

(46.116, 47.442] 8

(73.973, 75.3] 5

(66.014, 67.341] 2

(71.32, 72.647] 2

(64.687, 66.014] 1

(67.341, 68.667] 0

(68.667, 69.994] 0
(69.994, 71.32] 0

(72.647, 73.973] 0

Name: SiO2, dtype: int64

>>> df2=pd.value_counts(CI)

>>> df2.to_excel("Tugas.xlsx")

Traceback (most recent call last):

File "<stdin>", line 1, in <module>

File "C:\Users\asus\AppData\Local\Programs\Python\Python39\lib\site-packages\pandas\core\
generic.py", line 2284, in to_excel

formatter.write(

File "C:\Users\asus\AppData\Local\Programs\Python\Python39\lib\site-packages\pandas\io\formats\
excel.py", line 834, in write

writer = ExcelWriter( # type: ignore[abstract]

File "C:\Users\asus\AppData\Local\Programs\Python\Python39\lib\site-packages\pandas\io\excel\
_openpyxl.py", line 48, in __init__

from openpyxl.workbook import Workbook

ModuleNotFoundError: No module named 'openpyxl'

>>> sns.ecdfplot(data=df, x="SiO2")

<AxesSubplot:xlabel='SiO2', ylabel='Proportion'>

>>> plt.show()

>>> sns.ecdfplot(data=df, x="SiO2", hue="Vol")

<AxesSubplot:xlabel='SiO2', ylabel='Proportion'>

>>> plt.show()

>>> from scipy import mean

>>> ar_mean=mean(df)

<stdin>:1: DeprecationWarning: scipy.mean is deprecated and will be removed in SciPy 2.0.0, use
numpy.mean instead

C:\Users\asus\AppData\Local\Programs\Python\Python39\lib\site-packages\numpy\core\
fromnumeric.py:3438: FutureWarning: Dropping of nuisance columns in DataFrame reductions (with
'numeric_only=None') is deprecated; in a future version this will raise TypeError. Select only valid
columns before calling the reduction.
return mean(axis=axis, dtype=dtype, out=out, **kwargs)

>>> print(ar_mean)

SiO2 54.258760

MgO 3.040846

dtype: float64

>>> from scipy.stats import gmean

>>> x=df["SiO2"].values #

>>> geo_mean=gmean(x)

>>> print(geo_mean)

54.12558033650767

>>> from scipy.stats import hmean

>>> har_mean=hmean(x)

>>> print(har_mean)

53.99898217964356

>>> from scipy.stats import mode

>>> mode(df)

ModeResult(mode=array([['Merapi', 49.7, 2.39]], dtype=object), count=array([[413, 5, 9]]))

>>> ax=sns.boxplot(x="Group", y="B/Nb", data=df)

Traceback (most recent call last):

File "<stdin>", line 1, in <module>

File "C:\Users\asus\AppData\Local\Programs\Python\Python39\lib\site-packages\seaborn\
_decorators.py", line 46, in inner_f

return f(**kwargs)

File "C:\Users\asus\AppData\Local\Programs\Python\Python39\lib\site-packages\seaborn\
categorical.py", line 2243, in boxplot

plotter = _BoxPlotter(x, y, hue, data, order, hue_order,

File "C:\Users\asus\AppData\Local\Programs\Python\Python39\lib\site-packages\seaborn\
categorical.py", line 406, in __init__

self.establish_variables(x, y, hue, data, orient, order, hue_order)


File "C:\Users\asus\AppData\Local\Programs\Python\Python39\lib\site-packages\seaborn\
categorical.py", line 153, in establish_variables

raise ValueError(err)

ValueError: Could not interpret input 'Group'

>>> ax=sns.boxplot(x="malik", y="B/Nb", data=df)

Traceback (most recent call last):

File "<stdin>", line 1, in <module>

File "C:\Users\asus\AppData\Local\Programs\Python\Python39\lib\site-packages\seaborn\
_decorators.py", line 46, in inner_f

return f(**kwargs)

File "C:\Users\asus\AppData\Local\Programs\Python\Python39\lib\site-packages\seaborn\
categorical.py", line 2243, in boxplot

plotter = _BoxPlotter(x, y, hue, data, order, hue_order,

File "C:\Users\asus\AppData\Local\Programs\Python\Python39\lib\site-packages\seaborn\
categorical.py", line 406, in __init__

self.establish_variables(x, y, hue, data, orient, order, hue_order)

File "C:\Users\asus\AppData\Local\Programs\Python\Python39\lib\site-packages\seaborn\
categorical.py", line 153, in establish_variables

raise ValueError(err)

ValueError: Could not interpret input 'malik'

>>> ax=sns.boxplot(x="Group", y="B/Nb", data=df)

Traceback (most recent call last):

File "<stdin>", line 1, in <module>

File "C:\Users\asus\AppData\Local\Programs\Python\Python39\lib\site-packages\seaborn\
_decorators.py", line 46, in inner_f

return f(**kwargs)

File "C:\Users\asus\AppData\Local\Programs\Python\Python39\lib\site-packages\seaborn\
categorical.py", line 2243, in boxplot

plotter = _BoxPlotter(x, y, hue, data, order, hue_order,

File "C:\Users\asus\AppData\Local\Programs\Python\Python39\lib\site-packages\seaborn\
categorical.py", line 406, in __init__

self.establish_variables(x, y, hue, data, orient, order, hue_order)


File "C:\Users\asus\AppData\Local\Programs\Python\Python39\lib\site-packages\seaborn\
categorical.py", line 153, in establish_variables

raise ValueError(err)

ValueError: Could not interpret input 'Group'

>>> ax=sns.swarmplot(x="Group", y="B/Nb", data=df, color=".25")

Traceback (most recent call last):

File "<stdin>", line 1, in <module>

File "C:\Users\asus\AppData\Local\Programs\Python\Python39\lib\site-packages\seaborn\
_decorators.py", line 46, in inner_f

return f(**kwargs)

File "C:\Users\asus\AppData\Local\Programs\Python\Python39\lib\site-packages\seaborn\
categorical.py", line 3004, in swarmplot

plotter = _SwarmPlotter(x, y, hue, data, order, hue_order,

File "C:\Users\asus\AppData\Local\Programs\Python\Python39\lib\site-packages\seaborn\
categorical.py", line 1172, in __init__

self.establish_variables(x, y, hue, data, orient, order, hue_order)

File "C:\Users\asus\AppData\Local\Programs\Python\Python39\lib\site-packages\seaborn\
categorical.py", line 153, in establish_variables

raise ValueError(err)

ValueError: Could not interpret input 'Group'

>>>

You might also like