Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
44 changes: 44 additions & 0 deletions Central Limit Theorem.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env python
# coding: utf-8

# In[22]:


import numpy
import matplotlib.pyplot as plt
import seaborn as sns

# number of sample
num = [1, 10, 50, 100]
# list of sample means
means = []

# Generating 1, 10, 30, 100 random numbers from -40 to 40
# taking their mean and appending it to list means.
for j in num:
# Generating seed so that we can get same result
# every time the loop is run...
numpy.random.seed(1)
x = [numpy.mean(
numpy.random.binomial(
1, 0.5, j)) for _i in range(1000)]
means.append(x)

k = 0
print(numpy.shape(means))
# plotting all the means in one figure
fig, ax = plt.subplots(2, 2, figsize =(8, 8))
for i in range(0, 2):
for j in range(0, 2):
# Histogram for each x stored in means

ax[i, j].hist(means[k], 100, density = True)
ax[i, j].set_title(label = num[k])
k = k + 1

plt.show()

#what about binomial distribution?
#[numpy.mean(
#numpy.random.binomial(
# 1, 0.5, j)) for _i in range(1000)]
210 changes: 210 additions & 0 deletions Summary Statistic and Visualisation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
#!/usr/bin/env python
# coding: utf-8

# In[1]:


import math
import statistics
import numpy as np
import scipy.stats
import pandas as pd


# In[3]:


x = [8.0, 1, 2.5, 4, 28.0]
x_with_nan = [8.0, 1, 2.5, math.nan, 4, 28.0]

print(x)
print(x_with_nan)


# In[5]:


math.isnan(np.nan),np.isnan(math.nan)


# In[15]:


y, y_with_nan = np.array(x), np.array(x_with_nan)
z, z_with_nan = pd.Series(x), pd.Series(x_with_nan)
print("-------y------")
print(y)
print("-------y_with_nan------")
print(y_with_nan)
print("-------z------")
print(z)
print("-------z_with_nan------")
print(z_with_nan)


# In[16]:


mean_ = sum(x) / len(x)
mean_


# In[6]:


# Descriptive Statistics


# In[7]:


#Create a Dictionary of series
d = {'Name':pd.Series(['Ahmet','Mehmet','Ayse','Berk','Mahmut','Aylin','Kazim',
'Lee','Temel','Gasper','Fatma','Elif']),
'Age':pd.Series([25,26,25,23,30,29,23,34,40,30,51,46]),
'Rating':pd.Series([4.23,3.24,3.98,2.56,3.20,4.6,3.8,3.78,2.98,4.80,4.10,3.65])
}

#Create a DataFrame
df = pd.DataFrame(d)
print(df)


# In[8]:


#Create a DataFrame
df = pd.DataFrame(d)
#summation
print(df.sum())


# In[11]:


#select a column
df['Age'].sum()


# In[12]:


#apply a desired funtion on specified column(s)
print("----VAR------")
print(df[['Age','Rating']].var())

print("----STD----")
print(df[['Age','Rating']].std())


# In[ ]:


#Sr.No. Function Description
#1 count() Number of non-null observations
#2 sum() Sum of values
#3 mean() Mean of Values
#4 median() Median of Values
#5 mode() Mode of values
#6 std() Standard Deviation of the Values
#7 var() Variance of the Values
#8 min() Minimum Value
#9 max() Maximum Value
#10 abs() Absolute Value
#11 prod() Product of Values
#12 cumsum() Cumulative Sum
#13 cumprod() Cumulative Product


# In[13]:


print(df.describe())


# In[54]:


#Python Pandas - Visualization


# In[26]:


#np.random.seed(123)
df = pd.DataFrame(np.random.randn(10,4),index=pd.date_range('1/1/2000',
periods=10), columns=list('ABCD'))
x
df


# In[27]:


df.describe()
#notice on the mean and std


# In[28]:


df.plot()


# In[30]:


#only non zero values
nanzero_df = pd.DataFrame(np.random.rand(10,4),columns=['a','b','c','d'])
nanzero_df.plot.bar()


# In[90]:


nanzero_df.plot.bar(stacked=True)


# In[92]:


#horizontal
nanzero_df.plot.barh(stacked=True)


# In[33]:


df = pd.DataFrame({'a':np.random.randn(1000),'b':np.random.randn(1000),'c':
np.random.randn(1000)}, columns=['a', 'b', 'c'])

#df.plot.hist(bins=20)
df.describe()
df['a'].plot.hist(bins=20)


# In[34]:


df.plot.box()


# In[113]:


df = pd.DataFrame(np.random.rand(10, 4), columns=['a', 'b', 'c', 'd'])
df.plot.area()


# In[114]:


df = pd.DataFrame(np.random.rand(50, 4), columns=['a', 'b', 'c', 'd'])
df.plot.scatter(x='a', y='b')


# In[116]:


df = pd.DataFrame(3 * np.random.rand(4), index=['a', 'b', 'c', 'd'], columns=['x'])
df.plot.pie(subplots=True)
111 changes: 111 additions & 0 deletions env/Lib/site-packages/PIL/BdfFontFile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
#
# The Python Imaging Library
# $Id$
#
# bitmap distribution font (bdf) file parser
#
# history:
# 1996-05-16 fl created (as bdf2pil)
# 1997-08-25 fl converted to FontFile driver
# 2001-05-25 fl removed bogus __init__ call
# 2002-11-20 fl robustification (from Kevin Cazabon, Dmitry Vasiliev)
# 2003-04-22 fl more robustification (from Graham Dumpleton)
#
# Copyright (c) 1997-2003 by Secret Labs AB.
# Copyright (c) 1997-2003 by Fredrik Lundh.
#
# See the README file for information on usage and redistribution.
#

"""
Parse X Bitmap Distribution Format (BDF)
"""


from . import FontFile, Image

bdf_slant = {
"R": "Roman",
"I": "Italic",
"O": "Oblique",
"RI": "Reverse Italic",
"RO": "Reverse Oblique",
"OT": "Other",
}

bdf_spacing = {"P": "Proportional", "M": "Monospaced", "C": "Cell"}


def bdf_char(f):
# skip to STARTCHAR
while True:
s = f.readline()
if not s:
return None
if s[:9] == b"STARTCHAR":
break
id = s[9:].strip().decode("ascii")

# load symbol properties
props = {}
while True:
s = f.readline()
if not s or s[:6] == b"BITMAP":
break
i = s.find(b" ")
props[s[:i].decode("ascii")] = s[i + 1 : -1].decode("ascii")

# load bitmap
bitmap = []
while True:
s = f.readline()
if not s or s[:7] == b"ENDCHAR":
break
bitmap.append(s[:-1])
bitmap = b"".join(bitmap)

[x, y, l, d] = [int(p) for p in props["BBX"].split()]
[dx, dy] = [int(p) for p in props["DWIDTH"].split()]

bbox = (dx, dy), (l, -d - y, x + l, -d), (0, 0, x, y)

try:
im = Image.frombytes("1", (x, y), bitmap, "hex", "1")
except ValueError:
# deal with zero-width characters
im = Image.new("1", (x, y))

return id, int(props["ENCODING"]), bbox, im


class BdfFontFile(FontFile.FontFile):
"""Font file plugin for the X11 BDF format."""

def __init__(self, fp):
super().__init__()

s = fp.readline()
if s[:13] != b"STARTFONT 2.1":
msg = "not a valid BDF file"
raise SyntaxError(msg)

props = {}
comments = []

while True:
s = fp.readline()
if not s or s[:13] == b"ENDPROPERTIES":
break
i = s.find(b" ")
props[s[:i].decode("ascii")] = s[i + 1 : -1].decode("ascii")
if s[:i] in [b"COMMENT", b"COPYRIGHT"]:
if s.find(b"LogicalFontDescription") < 0:
comments.append(s[i + 1 : -1].decode("ascii"))

while True:
c = bdf_char(fp)
if not c:
break
id, ch, (xy, dst, src), im = c
if 0 <= ch < len(self.glyph):
self.glyph[ch] = xy, dst, src, im
Loading