This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from IPython.display import Markdown, display | |
def printmd(string, color=None): | |
colorstr = "<span style='color:{}'>{}</span>".format(color, string) | |
display(Markdown(colorstr)) | |
printmd("**bold and blue**", color="blue") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ls dir1/dir2/*.txt | xargs -n 1 basename |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.apply(pd.to_numeric,errors='coerce') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import matplotlib.pyplot as plt | |
from numpy.random import random | |
t = np.linspace(0, 1, 101) | |
plt.figure() | |
plt.subplot(2, 2, 1); plt.hist(random(20)) | |
plt.subplot(2, 2, 2); plt.plot(t, t**2, t, t**3 - t) | |
plt.subplot(2, 2, 3); plt.plot(random(20), random(20), 'r*') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
t = np.linspace(0, 5*np.pi, 501) # Define parameter for parametric plot. | |
plt.plot(t, np.sin(t)**2) # Generate plot. | |
plt.plot(t, np.sin(t)**3) # Create new plot on same axes. | |
ax = plt.gca() # Gain control of axes. | |
ax.hold(False) # Turn hold off. | |
plt.plot(t, np.sin(t)**4) # Create new plot; old data erased. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data = [[2000, 2000, 2000, 2001, 2001, 2001, 2002, 2002, 2002], | |
['Jan', 'Feb', 'Mar', 'Jan', 'Feb', 'Mar', 'Jan', 'Feb', 'Mar'], | |
[1, 2, 3, 4, 5, 6, 7, 8, 9]] | |
rows = list(zip(data[0], data[1], data[2])) | |
headers = ['Year', 'Month', 'Value'] | |
df = pd.DataFrame(rows, columns=headers) | |
pivot_df = df.pivot(index='Year', columns='Month', values='Value') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
df.set_index('First_col').T.plot(kind='bar', stacked=True,figsize=(16,8)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%matplotlib inline | |
from pandas import Series | |
import matplotlib.pyplot as plt | |
heights = Series( | |
[165, 170, 195, 190, 170, | |
170, 185, 160, 170, 165, | |
185, 195, 185, 195, 200, | |
195, 185, 180, 185, 195], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import string | |
df = pd.DataFrame({'c0':range(1,10), 'c1': list(string.ascii_letters[0:9])}) | |
df2 = df.iloc[[0, -1]] | |
# first and last 10 | |
df = pd.concat([df.head(10), df.tail(10)]) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import calendar | |
# Ref: https://docs.python.org/2/library/datetime.html | |
df['release_year'] = pd.to_datetime(df['release_date'], format='%m/%d/%y') | |
df['release_month'] = df['release_year'].dt.month |