Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- "cells": [
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "<table>\n",
- "<tr>\n",
- "<th>dna_seq</th>\n",
- "<th>length</th>\n",
- "</tr>\n",
- "<tr>\n",
- "<td><span style = \"color: blue;\">A</span><span style = \"color: red;\">C</span><span style = \"color: green;\">G</span><span style = \"color: yellow;\">T</span><span style = \"color: green;\">G</span><span style = \"color: red;\">C</span><span style = \"color: blue;\">A</span></td>\n",
- "<td>7</td>\n",
- "</tr>\n",
- "<tr>\n",
- "<td><span style = \"color: blue;\">A</span><span style = \"color: red;\">C</span><span style = \"color: red;\">C</span></td>\n",
- "<td>3</td>\n",
- "</tr>\n",
- "</table>\n"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 29,
- "metadata": {
- "collapsed": false
- },
- "outputs": [
- {
- "data": {
- "text/html": [
- "<div>\n",
- "<table border=\"0\" class=\"dataframe\">\n",
- " <thead>\n",
- " <tr style=\"text-align: right;\">\n",
- " <th></th>\n",
- " <th>dna_seq</th>\n",
- " <th>length</th>\n",
- " </tr>\n",
- " </thead>\n",
- " <tbody>\n",
- " <tr>\n",
- " <th>0</th>\n",
- " <td>ACGTGCA</td>\n",
- " <td>7</td>\n",
- " </tr>\n",
- " <tr>\n",
- " <th>1</th>\n",
- " <td>ACC</td>\n",
- " <td>3</td>\n",
- " </tr>\n",
- " </tbody>\n",
- "</table>\n",
- "</div>"
- ],
- "text/plain": [
- " dna_seq length\n",
- "0 ACGTGCA 7\n",
- "1 ACC 3"
- ]
- },
- "execution_count": 29,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "df = pd.DataFrame({\"dna_seq\": [\"ACGTGCA\", \"ACC\"],\n",
- " \"length\": [7, 3]})\n",
- "df"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 28,
- "metadata": {
- "collapsed": false
- },
- "outputs": [
- {
- "data": {
- "text/html": [
- "\n",
- " <style type=\"text/css\" >\n",
- " \n",
- " \n",
- " </style>\n",
- "\n",
- " <table id=\"T_4b732318_54c9_11e6_b822_a45e60bd97fb\" None>\n",
- " \n",
- "\n",
- " <thead>\n",
- " \n",
- " <tr>\n",
- " \n",
- " <th class=\"blank\">\n",
- " \n",
- " <th class=\"col_heading level0 col0\">dna_seq\n",
- " \n",
- " <th class=\"col_heading level0 col1\">length\n",
- " \n",
- " </tr>\n",
- " \n",
- " </thead>\n",
- " <tbody>\n",
- " \n",
- " <tr>\n",
- " \n",
- " <th id=\"T_4b732318_54c9_11e6_b822_a45e60bd97fb\" class=\"row_heading level1 row0\">\n",
- " 0\n",
- " \n",
- " <td id=\"T_4b732318_54c9_11e6_b822_a45e60bd97fbrow0_col0\" class=\"data row0 col0\">\n",
- " <span style=\"color: blue\">A</span><span style=\"color: red\">C</span><span style=\"color: green\">G</span><span style=\"color: yellow\">T</span><span style=\"color: green\">G</span><span style=\"color: red\">C</span><span style=\"color: blue\">A</span>\n",
- " \n",
- " <td id=\"T_4b732318_54c9_11e6_b822_a45e60bd97fbrow0_col1\" class=\"data row0 col1\">\n",
- " 7\n",
- " \n",
- " </tr>\n",
- " \n",
- " <tr>\n",
- " \n",
- " <th id=\"T_4b732318_54c9_11e6_b822_a45e60bd97fb\" class=\"row_heading level1 row1\">\n",
- " 1\n",
- " \n",
- " <td id=\"T_4b732318_54c9_11e6_b822_a45e60bd97fbrow1_col0\" class=\"data row1 col0\">\n",
- " <span style=\"color: blue\">A</span><span style=\"color: red\">C</span><span style=\"color: red\">C</span>\n",
- " \n",
- " <td id=\"T_4b732318_54c9_11e6_b822_a45e60bd97fbrow1_col1\" class=\"data row1 col1\">\n",
- " 3\n",
- " \n",
- " </tr>\n",
- " \n",
- " </tbody>\n",
- " </table>\n",
- " "
- ],
- "text/plain": [
- "<pandas.formats.style.Styler at 0x10b31f358>"
- ]
- },
- "execution_count": 28,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "def formatter(v):\n",
- " cmap = {\"A\": \"blue\", \"C\": \"red\", \"G\": \"green\", \"T\": \"yellow\"}\n",
- " return ''.join(['<span style=\"color: {}\">{}</span>'.format(cmap[s], s)\n",
- " for s in v])\n",
- " \n",
- "\n",
- "df.style.format({\"dna_seq\": formatter})"
- ]
- }
- ],
- "metadata": {
- "kernelspec": {
- "display_name": "Python 3",
- "language": "python",
- "name": "python3"
- },
- "language_info": {
- "codemirror_mode": {
- "name": "ipython",
- "version": 3
- },
- "file_extension": ".py",
- "mimetype": "text/x-python",
- "name": "python",
- "nbconvert_exporter": "python",
- "pygments_lexer": "ipython3",
- "version": "3.5.2"
- }
- },
- "nbformat": 4,
- "nbformat_minor": 0
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement