Skip to content

Instantly share code, notes, and snippets.

View bhishanpdl's full-sized avatar

Bhishan Poudel bhishanpdl

View GitHub Profile
@bhishanpdl
bhishanpdl / fits_combine_jedisim_two.py
Created September 4, 2018 14:10
Add two fits files from jedisim outputs with jedism settings headers.
#!python
# -*- coding: utf-8 -*-#
"""
Create fitsfile.
Author : Bhishan Poudel
Date : Sep 4, 2018
Combine two fitsfile keeping their fitsheaders.
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')
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')
def clean_data(data):
"""
Clean the pandas dataframe.
data: pandas dataframe
return: cleaned dataframe
1. Make column names lowercase and underscored.
%%bash
cat > out.csv << EOL
lines
EOL
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
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)])
@bhishanpdl
bhishanpdl / barplot_mean.py
Created August 31, 2018 20:40
Plot vertical bar plot with mean line.
%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],
@bhishanpdl
bhishanpdl / pandas_plot.py
Created August 31, 2018 20:19
Plotting with pandas
df.set_index('First_col').T.plot(kind='bar', stacked=True,figsize=(16,8))