DEV Community

Cover image for Load Pokemon data into Postgres
Kaushik Varanasi
Kaushik Varanasi

Posted on • Updated on

Load Pokemon data into Postgres

Load the Pokemon data

Let's load the Pokemon data from the open-source db. We'll need a small standalone Python project for that.

Create a folder called pokemon-python and a file named load_pokemon.py:

import pandas as pd
from sqlalchemy import create_engine
engine = create_engine('postgresql://postgres:password@xxxxx.xxxxx.us-east-2.rds.amazonaws.com:5432/postgres')
df=pd.read_csv('https://raw.githubusercontent.com/veekun/pokedex/master/pokedex/data/csv/pokemon.csv')
df.to_sql('pokemon', engine)
Enter fullscreen mode Exit fullscreen mode
cd pokemon-python
Enter fullscreen mode Exit fullscreen mode
# create a venv
pip install virtualenv
python3 -m venv env
Enter fullscreen mode Exit fullscreen mode
# To activate
source env/bin/activate
Enter fullscreen mode Exit fullscreen mode

For an easier and robust deployment of Postgres instances, checkout Rocketgraph

pip3 install pandas
pip3 install sqlalchemy
Enter fullscreen mode Exit fullscreen mode

And for good measure

pip3 freeze > requirements.txt
Enter fullscreen mode Exit fullscreen mode

Now simply run

python3 load_pokemon.py
Enter fullscreen mode Exit fullscreen mode

if you get an error such as

ModuleNotFoundError: No module named 'psycopg2'

simply install it:

pip install psycopg2-binary
Enter fullscreen mode Exit fullscreen mode

Once you run that command, psql into your PostgresDB to ensure that Pokemon data is loaded:

psql postgresql://postgres:password@restless-pine.xxxxxxxxxxx.us-east-2.rds.amazonaws.com:5432/postgres
Enter fullscreen mode Exit fullscreen mode

And:

SELECT * FROM pokemon LIMIT 10;
Enter fullscreen mode Exit fullscreen mode

You should see a few Pokemon there. Congrats, you loaded the Pokemon data and setup a front-end succesfully.

Top comments (0)