Skip to content

Instantly share code, notes, and snippets.

@hendrik-goebel
Created September 20, 2020 08:41
Show Gist options
  • Save hendrik-goebel/07307d41458040d31a583963268d3da8 to your computer and use it in GitHub Desktop.
Save hendrik-goebel/07307d41458040d31a583963268d3da8 to your computer and use it in GitHub Desktop.
Pandas Snippets (Jupyter Notebook)
#!/usr/bin/env python
# coding: utf-8
# In[ ]:
import as pd
import numpy as np
# # Pandas Snippets
# ## Create new DataFrame
# In[32]:
# Create array of random numbers
a = np.random.randint(1,100,20)
b = np.random.randint(1,100,20)
# Combine the two columns
c = zip(a,b)
# Create array of time series
d = pd.date_range('1/1/2012', periods=20, freq='H')
# Create dataframe with time series index
df = pd.DataFrame(c, index=d, columns=['COL1', 'COL2'])
print(df)
# ## Describe statistical properties
# In[33]:
print( df.describe())
# ## Kurtosis and Skewness
#
# axis=0: go along columns
#
# axis=: go along rows
# In[35]:
print ( df.kurtosis(axis=0))
# In[43]:
df.skew(axis=0)
# ## Plotting
# In[36]:
df.plot()
# ## Distribution
# In[39]:
df.plot.hist(alpha=0.5, bins=12)
# ## Correlation
# In[40]:
correlation = df.corr()
print(correlation)
# ### Correlation heatmap
# In[41]:
import seaborn as sns
sns.heatmap(correlation)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment