130.000 rent and sale housing ads of Barcelona municipality in a free .csv file
APIDataPython
Introduction
Housing (and of course, its price) is perceived by the spanish citizen as one of the main problems of Spain in the year 2023:
Several real estate experts have proposed to publish the real estate transaction prices for each house code, as a measure of lowering the price of the Spanish real estate.
The Spanish "catastral code" is an unique id that describes every real estate item in Spain (except the Basque Country and Navarra).
How to get the Spanish real estate data?
To have a complete picture of the Spanish real estate market it would be necessary to know the sale and rental prices of properties.
True sales and purchase prices are only available to notaries and Spanish property registration. This price may not be completely reliable because in some transactions it is agreed to pay in cash (payment in B) a part of the property to obtain tax advantages.
True rental data prices are only in the hands of real estate agencies (and their groups), introducing biases in the price since rentals between individuals are not taken into account.
This data is either not accessible or the cost is prohibitive.
Other options to obtain data on the Spanish real estate market go through real estate portals. These data indicate the price desired by the bidder, but not the final price. Even so, they are data that, treated properly, can be interesting.
Idealista.com is the market leader in real estate ads in Spain (Italy and Portugal).
The Data
During 2023, around 130,000 housing advertisements were published in the municipality of Barcelona.
To make the information manageable in a csv file, each ad/record has been reduced to the data in the table below. As you can see, in addition to the name of the column, the number of instances and their description are indicated:
This is one example of a housing record/add:
2023 Barcelona Housing CSV
The most efficient way (not counting a public API) to share this information is through a csv file. To do this, the data from a DB has been passed to a Python dataframe through a query from the Django ORM (later with FastAPI to improve times and efficiency) and then we use the df.to_csv() function. The entire process takes about 10 seconds (although it could be optimized):
If you do not have experience with the Python pandas library, it is recommended to use VisiData to explore large csv files.
More information
As I mentioned above, this csv file is a small sample of the information available:
Other types of properties such as offices, garages, rooms…
8,130 more municipalities (besides Barcelona)
Spatial information of the different geographical areas