Sample data created with python

Sample data

Linear data

n=20
a = np.arange(n).reshape(4, -1); a  #5-column matrix
array([[ 0,  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, 86, 87, 88, 89, 90, 91,
        92, 93, 94, 95, 96, 97, 98, 99]])
df = pd.DataFrame(a, columns=list('abcde')); df
a b c d e
0 0 1 2 3 4
1 5 6 7 8 9
2 10 11 12 13 14
3 15 16 17 18 19

Random data

r = np.random.randn(4, 5); r
array([[-0.37840346, -0.84591793,  0.50590263,  0.0544243 ,  0.59361247],
       [-0.2726931 , -1.74415635,  0.0199559 , -0.20695113, -1.19559455],
       [-0.59799566, -0.26810224, -0.18738038,  1.05843686,  0.72317579],
       [ 1.23389386,  1.91293041, -1.33322818,  0.78255026,  2.04737357]])
df = pd.DataFrame(r, columns=list('abcde')); df
a b c d e
0 -0.378403 -0.845918 0.505903 0.054424 0.593612
1 -0.272693 -1.744156 0.019956 -0.206951 -1.195595
2 -0.597996 -0.268102 -0.187380 1.058437 0.723176
3 1.233894 1.912930 -1.333228 0.782550 2.047374
df.plot()
<matplotlib.axes._subplots.AxesSubplot at 0x17699af2a58>

output_8_1.png

df = pd.DataFrame(np.random.randn(n,n))
plt.contourf(df, cmap='jet')
<matplotlib.contour.QuadContourSet at 0x1769a1a12b0>

output_10_1.png

Contour line display

plt.pcolor(df, cmap='jet')
<matplotlib.collections.PolyCollection at 0x1769b1e2208>

output_12_1.png

Color map display

sin wave

n=100
x = np.linspace(0, 2*np.pi, n)
s = pd.Series(np.sin(x), index=x)
s.plot()
<matplotlib.axes._subplots.AxesSubplot at 0x1769e695780>

output_16_1.png

sin wave

snoise = s + 0.1 * np.random.randn(n)
sdf = pd.DataFrame({'sin wave':s, 'noise wave': snoise})
sdf.plot(color=('r', 'b'))
<matplotlib.axes._subplots.AxesSubplot at 0x1769e8586d8>

output_18_1.png

I put noise on it

normal distribution

from  scipy import stats as ss
median = x[int(n/2)]  #Median of x
g = pd.Series(ss.norm.pdf(x, loc=median), x)
g.plot()
<matplotlib.axes._subplots.AxesSubplot at 0x1769ffba128>

output_22_1.png

gnoise = g + 0.01 * np.random.randn(n)
df = pd.DataFrame({'gauss wave':g, 'noise wave': gnoise})
df.plot(color=('r', 'b'))
<matplotlib.axes._subplots.AxesSubplot at 0x1769e970828>

output_23_1.png

log function

median = x[int(n/2)]  #Median of x
x1 = x + 10e-3
l = pd.Series(np.log(x1), x1)
l.plot()
<matplotlib.axes._subplots.AxesSubplot at 0x1769ffba5f8>

output_25_1.png

lnoise = l + 0.1 * np.random.randn(n)
df = pd.DataFrame({'log wave':l, 'noise wave': lnoise})
df.plot(color=('r', 'b'))
<matplotlib.axes._subplots.AxesSubplot at 0x176a00ec358>

output_26_1.png

Random walk

n = 1000
se = pd.Series(np.random.randint(-1, 2, n)).cumsum()
se.plot()
<matplotlib.axes._subplots.AxesSubplot at 0x284f3c62c18>

README_28_1.png

Random walk is drawn by randomly generating n of (-1, 0, 1) with np.random.randint (-1, 2, n) and accumulating them with cumsum ().

sma100 = se.rolling(100).mean()
ema100 = se.ewm(span=100).mean()

df = pd.DataFrame({'Chart': se,  'SMA100': sma100, 'EMA100': ema100})
df.plot(style = ['--','-','-'])
<matplotlib.axes._subplots.AxesSubplot at 0x284f3cadcc0>

README_30_1.png

A Simple Moving Average and an Exponential Moving Average were drawn at the same time. It is generally said that EMA is easier to reflect the latest movements and follow trends than SMA.

It has nothing to do with the content of the article, but if you write it in jupyter notebook and drop it in md format, it's really easy because you only have to attach it to qiita.

Recommended Posts

Sample data created with python
Data analysis with python 2
Data analysis with Python
Get Youtube data with python
Read json data with python
[Python] Get economic data with DataReader
Python data structures learned with chemoinformatics
Easy data visualization with Python seaborn.
Process Pubmed .xml data with python
Data analysis starting with python (data visualization 1)
Data analysis starting with python (data visualization 2)
Python application: Data cleansing # 2: Data cleansing with DataFrame
Subtitle data created with Amazon Transcribe
Get additional data in LDAP with python
Data pipeline construction with Python and Luigi
FizzBuzz with Python3
Receive textual data from mysql with python
Scraping with Python
[Note] Get data from PostgreSQL with Python
Statistics with python
Process Pubmed .xml data with python [Part 2]
Scraping with Python
Add a Python data source with Redash
Retrieving food data with Amazon API (Python)
Python with Go
Try working with binary data in Python
Data analysis python
Generate Japanese test data with Python faker
Twilio with Python
Python closure sample
Convert Excel data to JSON with python
Integrate with Python
[Python] Use string data with scikit-learn SVM
Download Japanese stock price data with python
Play with 2016-Python
AES256 with python
Tested with Python
Manipulate DynamoDB data with Lambda (Node & Python)
Convert FX 1-minute data to 5-minute data with Python
Created a darts trip with python (news)
python starts with ()
with syntax (Python)
Bingo with python
Zundokokiyoshi with python
Recommendation of Altair! Data visualization with Python
Data analysis starting with python (data preprocessing-machine learning)
Let's do MySQL data manipulation with Python
Organize data divided by folder with Python
[In-Database Python Analysis Tutorial with SQL Server 2017] Step 1: Download sample data
Process big data with Dataflow (ApacheBeam) + Python3
Excel with Python
[python] Read data
Microcomputer with Python
Sample to convert image to Wavelet with Python
Cast with python
How to create sample CSV data with hypothesis
Project cannot be created with Python3.5 (Windows) + django1.7.1
Create test data like that with Python (Part 1)
Read data with python / netCDF> nc.variables [] / Check data size
Generate two correlated pseudo-random numbers (with Python sample)
Read Python csv data with Pandas ⇒ Graph with Matplotlib