Home » Archives for Mark Needham » Page 4

Author Archives: Mark Needham

Python: Selecting certain indexes in an array

A couple of days ago I was scrapping the UK parliament constituencies from Wikipedia in preparation for the Graph Connect hackathon and had got to the point where I had an array with one entry per column in the table. import requests   from bs4 import BeautifulSoup from soupselect import select   page = open("constituencies.html", 'r') soup = BeautifulSoup(page.read())   ...

Read More »

Python: matplotlib hangs and shows nothing (Mac OS X)

I’ve been playing around with some of the matplotlib demos recently and discovered that simply copying one of the examples didn’t actually work for me. I was following the bar chart example and had the following code: When I execute this script from the command line it just hangs and I don’t see anything at all. Via a combination of ...

Read More »

Python: Streaming/Appending to a file

I’ve been playing around with Twitter’s API (via the tweepy library) and due to the rate limiting it imposes I wanted to stream results to a CSV file rather than waiting until my whole program had finished. I wrote the following program to simulate what I was trying to do:             The program will run ...

Read More »

Python/pandas: Column value in list

I’ve been using Python’s pandas library while exploring some CSV files and although for the most part I’ve found it intuitive to use, I had trouble filtering a data frame based on checking whether a column value was in a list. A subset of one of the CSV files I’ve been working with looks like this:         ...

Read More »

Python: Find the highest value in a group

In my continued playing around with a How I met your mother data set I needed to find out the last episode that happened in a season so that I could use it in a chart I wanted to plot. I had this CSV file containing each of the episodes:             I started out by ...

Read More »