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
#!python | |
# -*- coding: utf-8 -*-# | |
""" | |
Create fitsfile. | |
Author : Bhishan Poudel | |
Date : Sep 4, 2018 | |
Combine two fitsfile keeping their fitsheaders. |
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
ax = users['gender'].value_counts().plot(kind='barh') | |
for p in ax.patches: | |
ax.annotate(str(int(p.get_width())), (p.get_x() + p.get_width(), p.get_y()), xytext=(-2, 4), textcoords='offset points', horizontalalignment='right') |
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
ax = users['gender'].value_counts().plot(kind='bar') | |
for p in ax.patches: | |
ax.annotate(np.round(p.get_height(), decimals=2), | |
(p.get_x()+p.get_width()/2., | |
p.get_height()), ha='center', | |
va='center', xytext=(0, 10), | |
textcoords='offset points') |
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
def clean_data(data): | |
""" | |
Clean the pandas dataframe. | |
data: pandas dataframe | |
return: cleaned dataframe | |
1. Make column names lowercase and underscored. |
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
%%bash | |
cat > out.csv << EOL | |
lines | |
EOL |
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 |
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
%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
df.set_index('First_col').T.plot(kind='bar', stacked=True,figsize=(16,8)) |