Skip to content

Instantly share code, notes, and snippets.

View maria-aguilera's full-sized avatar

Maria Aguilera García maria-aguilera

View GitHub Profile
@huyng
huyng / matplotlibrc
Created February 8, 2011 15:50
my default matplotlib settings
### MATPLOTLIBRC FORMAT
# This is a sample matplotlib configuration file - you can find a copy
# of it on your system in
# site-packages/matplotlib/mpl-data/matplotlibrc. If you edit it
# there, please note that it will be overridden in your next install.
# If you want to keep a permanent local copy that will not be
# over-written, place it in HOME/.matplotlib/matplotlibrc (unix/linux
# like systems) and C:\Documents and Settings\yourname\.matplotlib
# (win32 systems).
@nanvel
nanvel / xmlparser.py
Created June 22, 2014 12:27
Lightweight xml parser
from xml import sax
class XMLParser(sax.handler.ContentHandler):
def __init__(self, keys=[], lists=[], *args, **kwargs):
"""
:param keys: list of data keys have to be available in data
:param lists: list of nodes have be represented as list
@Averroes
Averroes / example.py
Created April 10, 2015 18:30
parsing simple xml data
from urllib.request import urlopen
from xml.etree.ElementTree import parse
# Download the RSS feed and parse it
u = urlopen('http://planet.python.org/rss20.xml')
doc = parse(u)
# Extract and output tags of interest
for item in doc.iterfind('channel/item'):
title = item.findtext('title')
// XPath CheatSheet
// To test XPath in your Chrome Debugger: $x('/html/body')
// http://www.jittuu.com/2012/2/14/Testing-XPath-In-Chrome/
// 0. XPath Examples.
// More: http://xpath.alephzarro.com/content/cheatsheet.html
'//hr[@class="edge" and position()=1]' // every first hr of 'edge' class
@dyerrington
dyerrington / subplots.py
Created March 29, 2017 21:33
Plotting multiple figures with seaborn and matplotlib using subplots.
##
# Create a figure space matrix consisting of 3 columns and 2 rows
#
# Here is a useful template to use for working with subplots.
#
##################################################################
fig, ax = plt.subplots(figsize=(10,5), ncols=3, nrows=2)
left = 0.125 # the left side of the subplots of the figure
right = 0.9 # the right side of the subplots of the figure
@arunreddy
arunreddy / power_plots.py
Last active January 13, 2023 16:37
power_plots.py
# ---------------------------------------------------------
# library imports.
import numpy as np
import pandas as pd
from matplotlib import pyplot as plt
from matplotlib.dates import DateFormatter, DayLocator, HourLocator
# *********************************************************
@fomightez
fomightez / useful_pandas_snippets.py
Last active April 19, 2025 01:01 — forked from bsweger/useful_pandas_snippets.md
Useful Pandas Snippets
# List unique values in a DataFrame column
df['Column Name'].unique() # Note, `NaN` is included as a unique value. If you just want the number, use `nunique()` which stands
# for 'number of unique values'; By default, it excludes `NaN`. `.nunique(dropna=False)` will include `NaN` in the count of unique values.
# 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/)
@nandha005
nandha005 / XmlCsv_.idea_XmlCsv.iml
Created January 12, 2018 05:57
Xml to csv task
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="TestRunnerService">
<option name="PROJECT_TEST_RUNNER" value="Unittests" />
</component>
@ishashankverma
ishashankverma / ebox_parse.py
Created July 4, 2018 15:36
Parse function for parsing ebox url
import requests
import xml.etree.ElementTree as ET
url = 'http://test.cognizant.e-box.co.in/uploads/data_usage.xml'
# Getting the xml data from url
req = requests.get(url)
text = req.text
# Parsing the xml
root = ET.fromstring(text)
@estasney
estasney / extract_xml.py
Created July 13, 2018 01:46
Parsing XML of Stack Overflow Data Dumps
from gensim.utils import smart_open
from collections import defaultdict, OrderedDict
import csv
import xml.etree.ElementTree as ET
headers = ['AcceptedAnswerId', 'AnswerCount', 'ClosedDate', 'CommentCount', 'CommunityOwnedDate', 'CreationDate',
'FavoriteCount', 'Id', 'LastActivityDate', 'LastEditDate', 'LastEditorDisplayName', 'LastEditorUserId',
'OwnerDisplayName', 'OwnerUserId', 'ParentId', 'PostTypeId', 'Score', 'Tags', 'Title', 'ViewCount']
file_path = ""