Skip to content

Tag: database

Django change wrong column name in DB

in my Database (psql) I’ve got a table named offers_offer and inside that there is an column named offer_name, which is wrong, because it should actually be just name. I don’t know why it has this name, but due to this I can’t load any fixtures or create a new object, because I always receiv…

Replacing values greater than a number in pandas dataframe

I have a large dataframe which looks as: I want to replace each element greater than 9 with 11. So, the desired output for above example is: Edit: My actual dataframe has about 20,000 rows and each row has list of size 2000. Is there a way to use numpy.minimum function for each row? I assume that it will be

Database connection string parsing in python

Given a database connection string structure (such like one you can find here) what’s the best way to parse a real URI string and get their component like user, password, database name and host? Thank you very much Answer There is a Python library for that: python 2: urlparse python 3: urllib.parse

Get all keys in Redis database with python

There is a post about a Redis command to get all available keys, but I would like to do it with Python. Any way to do this? Answer Use scan_iter() scan_iter() is superior to keys() for large numbers of keys because it gives you an iterator you can use rather than trying to load all the keys into memory. I

Is there a way to get a list of column names in sqlite?

I want to get a list of column names from a table in a database. Using pragma I get a list of tuples with a lot of unneeded information. Is there a way to get only the column names? So I might end up with something like this: [Column1, Column2, Column3, Column4] The reason why I absolutely need this list

Select NULL Values in SQLAlchemy

Here’s my (PostgreSQL) table — I want to select all people that are not known to be married, i.e., including those with NULL marriage_status. This does not work — Of course this does — The problem is that I’m accessing it from SQLAlchemy with — which gets translated to &#82…