Home » Python (page 13)

Python

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 »

PyMongo And Key Order In Subdocuments

Or, "Why does my query work in the shell but not PyMongo?" Variations on this question account for a large portion of the Stack Overflow questions I see about PyMongo, so let me explain once for all. MongoDB stores documents in a binary format called BSON. Key-value pairs in a BSON document can have any order (except that _id is ...

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 Tutorial: Strings Datatype

Data stored in memory can of different types and Python like other languages have different standard data types. Sometime back we did a post on Python Numbers. Today we will be covering other standard datatypes i.e. Strings. Note: All examples shown in the post are based on python3. Like other languages, python also has the same meaning/definition for Strings. They are ...

Read More »