Skip to content

Instantly share code, notes, and snippets.

Avatar

Wayne's Bioinformatics Code Portal fomightez

View GitHub Profile
@fomightez
fomightez / useful_pandas_snippets.py
Last active March 25, 2023 22:01 — forked from bsweger/useful_pandas_snippets.md
Useful Pandas Snippets
View useful_pandas_snippets.py
# List unique values in a DataFrame column
df['Column Name'].unique()
# To extract a specific column (subset the dataframe), you can use [ ] (brackets) or attribute notation.
df.height
df['height']
# are same thing!!! (from http://www.stephaniehicks.com/learnPython/pages/pandas.html
# -or-
# http://www.datacarpentry.org/python-ecology-lesson/02-index-slice-subset/)
@fomightez
fomightez / remove blank lines regex.md
Last active March 25, 2023 18:53
remove all blank lines using regular expressions
View redirect_demo.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@fomightez
fomightez / useful_ipython_or_commandline_to_python_snippets.py
Last active March 3, 2023 21:47
Useful snippets and examples for when converting command line commands from Jupyter/IPython back to Pure Python
View useful_ipython_or_commandline_to_python_snippets.py
#Useful examples for when converting command line commands from Jupyter/IPython back to Pure Python
# This is party for when need to speed up a `.ipy` script running. It will run much faster as `.py` than as `.ipy` if there
# are a lot of calls to command line / shell commands because saves time by not spawning new shell instance for
# each. (`.ipy` version great for quicker development and proto-typing but `.py` MUCH FASTER for running.)
# The Python versions also have the advantage that you can use them inside functions (I think) because don't have problem like
# with `!cp fn unsanitized_{fn}`or `%store` where actually run in global namespace which cannot see Python variable `fn`
# local to the function.
# RELATED NOTE: You can use the IPython `history` (via the "hist command (with -n to remove line numbers)") to
# help convert `.ipy` code or Jupyter code with exclamation marks and shell commands BACK TO PYTHON, see
# https://stackoverflow.com/a/1040640/8508004 (especially also see the comment by Mic
View sales_data.csv
We can make this file beautiful and searchable if this error is corrected: Unclosed quoted field in line 5.
ORDERNUMBER,Quantity Ordered,Price Each,ORDERLINENUMBER,SALES,"ORDERDATE","STATUS",QTR_ID,Month,YEAR_ID,"Product",MSRP,"PRODUCTCODE","CUSTOMERNAME","PHONE","ADDRESSLINE1","ADDRESSLINE2","City","STATE","POSTALCODE","COUNTRY","TERRITORY","CONTACTLASTNAME","CONTACTFIRSTNAME"
10107,30,95.7,2,2871,"2/24/2003 0:00","Shipped",1,2,2003,"Motorcycles",95,"S10_1678","Land of Toys Inc.","2125557818","897 Long Airport Avenue",,"NYC","NY","10022","United States","NA","Yu","Kwai"
10121,34,81.35,5,2765.9,"5/7/2003 0:00","Shipped",2,5,2003,"Motorcycles",95,"S10_1678","Reims Collectables","26.47.1555","59 rue de l'Abbaye",,"Reims",,"51100","France","EMEA","Henriot","Paul"
10134,41,94.74,2,3884.34,"7/1/2003 0:00","Shipped",3,7,2003,"Motorcycles",95,"S10_1678","Lyon Souveniers","+33 1 46 62 7555","27 rue du Colonel Pierre Avia",,"Paris",,"75508","France","EMEA","Da Cunha","Daniel"
10145,45,83.26,6,3746.7,"8/25/2003 0:00","Shipped",3,8,2003,"Motorcycles",95,"S10_1678","Toys4GrownUps.com","6265557265","78934 Hillside Dr.",,"Pasade
@fomightez
fomightez / SortingBarPlotExample.ipynb
Last active January 31, 2023 11:35
llustrating Sorting bars in a Seaborn Bar Plot in Ascending Order Using Pandas
View SortingBarPlotExample.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@fomightez
fomightez / useful_python_snippets.py
Last active January 26, 2023 19:17
Useful Python snippets
View useful_python_snippets.py
# These are meant to work in both Python 2 and 3, except where noted.
# See my useful_pandas_snippets.py for those related to dataframes (such as pickling/`df.to_pickle(save_as)`)
# https://gist.github.com/fomightez/ef57387b5d23106fabd4e02dab6819b4
# also see https://gist.github.com/fomightez/324b7446dc08e56c83fa2d7af2b89a33 for examples of my
# frequently used Python functions and slight variations for more expanded, modular structures.
#argparse
# good snippet collection at https://mkaz.tech/code/python-argparse-cookbook/
@fomightez
fomightez / useful_notebook_snippets
Last active January 26, 2023 18:40
Useful snippets for Jupyter notebooks
View useful_notebook_snippets
# Use `%%capture` to hush 'noisy' stdout and stderr streams, but still combine with getting `%%time` after
%%capture out_stream
%%time
---rest of a cell that does something with LOTS of output--
#In cell after, put following to get time of completion from that:
#time it took to run cell above
for x in out_stream.stdout.split("\n")[-3:]:
print(x)
@fomightez
fomightez / try_Pylustrator_via_MyBinder.md
Last active January 16, 2023 21:44
Try Pylustrator right in your browser without installing anything on your system via temporary sessions served by MyBinder.org.
View try_Pylustrator_via_MyBinder.md

Walkthrough for installation and trial use of Pylustrator in your browser in temporary remote sessions served via MyBinder

Benefits:

  • Runs remotely so nothing modified on your machine yet you can test Pylustrator use hands-on.
  • Everything is already prepared, except for installation of the one package to be demonstrated.
  • No login required.

Options:

@fomightez
fomightez / demo_directions.md
Last active January 13, 2023 20:24
Using MyBinder to demo use of PySimpleGUI
View demo_directions.md

Using MyBinder to demo use of PySimpleGUI

Walkthrough for installation of PySimpleGUI and example use of PySimpleGUI in your browser in temporary remote sessions served via MyBinder

Benefits:

  • Runs remotely so nothing modified on your machine.
  • Everything is already prepared, except for installation of the one package to be demonstrated.