I’m generating a bar-chart with matplotlib. It all works well but I can’t figure out how to prevent the labels of the x-axis from overlapping each other. Here an example: Here is some sample SQL for a postgres 9.1 database: And this is my python-script: Is there a way how I can prevent the labels …
Tag: python
Sqlite executemany and DELETE
Execute many seems to be very slow with deletion (Insertion is fine) and I was wondering if anyone knows why it takes so long. Consider the code below: And the following time results (timeit was giving funny data so :/) from IPython: And just for the sake of completeness here are the timeit results (but I thi…
How to detect when a site check redirects to another page using the requests module?
For example, if I go to www.yahoo.com/thispage, and yahoo has set up a filter to redirect /thispage to /thatpage. So whenever someone goes to /thispage, they will land on /thatpage. If I use httplib/requests/urllib, will it know that there was a redirection? What error pages? Some sites redirect user to /erro…
A faster strptime?
I have code which reads vast numbers of dates in ‘YYYY-MM-DD’ format. Parsing all these dates, so that it can add one, two, or three days then write back in the same format is slowing things down quite considerably. Any suggestions how to speed it up a bit (or a lot)? Answer Python 3.7+: fromisofo…
How to drop rows of Pandas DataFrame whose value in a certain column is NaN
I have this DataFrame and want only the records whose EPS column is not NaN: …i.e. something like df.drop(….) to get this resulting dataframe: How do I do that? Answer Don’t drop, just take the rows where EPS is not NA:
T-test in Pandas
If I want to calculate the mean of two categories in Pandas, I can do it like this: I have a lot of data formatted this way, and now I need to do a T-test to see if the mean of cat1 and cat2 are statistically different. How can I do that? Answer it depends what sort of t-test you
Sorting out Django and MySQL in virtualenv
I’m following this tutorial to get started with Django, but I’m very confused about how to integrate MySQL. Doing this in the context of virtualenv (which is new to me) seems to complicate things even further. I’m running on Ubuntu and the MySQL server is on another host. Here are my specifi…
Is it possible to get an Excel document’s row count without loading the entire document into memory?
I’m working on an application that processes huge Excel 2007 files, and I’m using OpenPyXL to do it. OpenPyXL has two different methods of reading an Excel file – one “normal” method where the entire document is loaded into memory at once, and one method where iterators are used …
Python-Tornado on Heroku
I am trying to deploy Tornado on Heroku. I am able to run a simple “hello world” app on using this method: http://kzk9.net/deploying-tornado-on-heroku-mac-os-x But while trying Tornado demo-app “chatdemo”, the server is crashing with following logs: Anybody has any idea whats wrong? An…
Prepend the same string to all items in a list
Have done some searching through Stack Exchange answered questions but have been unable to find what I am looking for. Given the following list: How would I create: Thanks! Answer Use a list comprehension: A list comprehension lets you apply an expression to each element in a sequence. Here that expression is…