File size: 4,107 Bytes
f34b89f
 
 
 
 
 
4568718
 
f34b89f
 
d59ce22
f34b89f
 
 
 
 
 
5e87643
f34b89f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5e87643
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
---
license: apache-2.0
task_categories:
- feature-extraction
size_categories:
- 100M<n<1B
tags:
- geospatial
---

# Foursquare OS Places 100M

Full Foursquare OS Places dump from https://opensource.foursquare.com/os-places/.
This is a single (geo-)parquet file based on the 81 individual parquet files from fused.io on https://source.coop/fused/fsq-os-places/2024-11-19/places.

As it's just 10Gb, it's fairly easy to handle as a single file and can easily be queried over modern technologies like httpfs. 

## Ways to query the file & visualize the results
If you just want to poke around in the data to get an idea of kind of places to expect, I'd recommend DuckDB.
Huggingface has a DuckDB WASM console integrated but it's too slow (or runs out of memory) when run over the entire file. You can try it [here](https://huggingface.co/datasets/do-me/foursquare_places_100M?sql_console=true&sql=--+The+SQL+console+is+powered+by+DuckDB+WASM+and+runs+entirely+in+the+browser.%0A--+Get+started+by+typing+a+query+or+selecting+a+view+from+the+options+below.%0ASELECT+*+FROM+train+WHERE+name+ILIKE+%27%25bakery%25%27%3B%0A)

A better way is to run DuckDB locally and query it over httpfs (you do not need to download the whole file but thanks to modern range requests DuckDB just pulls the entries that match the query) as such, e.g. in  Python or in the CLI.
Here I use Jupyter and convert the results to a pandas view for displaying convenience.

### Example 1: Queried over httpfs with DuckDB

```python
import duckdb
duckdb.sql("INSTALL httpfs;LOAD httpfs;") # required extension
duckdb.sql(f"SELECT * FROM 'hf://datasets/do-me/foursquare_places_100M/foursquare_places.parquet' WHERE name ILIKE '%bakery%' ").df()
```

This command takes roughly 70 seconds on my system/network (M3 Max) and yields 104985 entries: 

![image/png](https://cdn-uploads.huggingface.co/production/uploads/64c4da8719565937fb268b32/LsCYG2HTQmO0t6cJa3Y3R.png)

### Example 2: Queried fully locally with DuckDB

This method is much faster, but you need to download the file once. Just download the file directly clicking [this link](https://huggingface.co/datasets/do-me/foursquare_places_100M/resolve/main/foursquare_places.parquet). 
You could also use Huggingface datasets library.

```python
import duckdb
duckdb.sql("SELECT * FROM 'foursquare_places.parquet' WHERE name ILIKE '%bakery%' ").df()
```

It yields precisely the same results but takes only 4.5 seconds! 

### Example 3: Queried fully locally with Geopandas

In case you'd like to do some easy geoprocessing, just stick to Geopandas. It's of course a bit slower and loads everything in memory but gets the job done nicely.

```python
import geopandas as gpd
gdf = gpd.read_parquet("foursquare_places.parquet")
```

Loading the gdf once takes 2 - 3 mins in my case.

Then you can make use of good old pandas query operators and geospatial tools. 

E.g. looking for bakeries again.
```python 
gdf[gdf["name"].str.contains("bakery")]
```
I was actually surprised that the string operator in pandas is that efficient! It only takes 11 seconds, so fairly fast for 100M rows!

But to be fair, the actual equivalent to ILIKE in pandas would be this query: 

```python
gdf[gdf["name"].str.contains("bakery", case=False, na=False)]
```

It yields exactly the same number of rows like the SQL command but takes 19 seconds, so - as expected - indeed much slower than DuckDB (especially considering that we just count the query time, not the loading time)

### Example 4: Queried fully locally with Geopandas and visualized with Lonboard

If you quickly want to visulize the data, Lonboard is a super convenient Jupyter wrapper for deck.gl. 
Install it with `pip install lonboard` and you're ready to go. 

```python
import geopandas as gpd
from lonboard import viz

gdf = gpd.read_parquet("foursquare_places.parquet")

bakeries = gdf[gdf["name"].str.contains("bakery", case=False, na=False)]

viz(bakeries)
```
It created a nice interactive map with tooltips.

![image/png](https://cdn-uploads.huggingface.co/production/uploads/64c4da8719565937fb268b32/QIolrK2nlrENnkWlE6TFh.png)