How would I go around creating a MYSQL table schema inspecting an Excel(or CSV) file. Are there any ready Python libraries for the task?
Column headers would be sanitized to column names. Datatype would be estimated based on the contents of the spreadsheet column. When done, data would be loaded to the table.
I have an Excel file of ~200 columns that I want to start normalizing.
Just for (my) reference, I documented below what I did:
LOAD DATA INFILE
CREATE TABLE
with all columns as TEXT, except for Primary keyLOAD DATA LOCAL INFILE
loading all CSV data into TEXT fields.PROCEDURE ANALYSE
, I was able to ALTER TABLE
to give columns the right types and lengths. PROCEDURE ANALYSE
returns ENUM
for any column with few distinct values, which is not what I needed, but I found that useful later for normalization. Eye-balling 200 columns was a breeze with PROCEDURE ANALYSE
. Output from PhpMyAdmin propose table structure was junk.SELECT DISTINCT
on columns and INSERT
ing results to separate tables. I have added to the old table a column for FK first. Just after the INSERT
, I've got its ID and UPDATE
ed the FK column. When loop finished I've dropped old column leaving only FK column. Similarly with multiple dependent columns. It was much faster than I expected.python manage.py inspctdb
, copied output to models.py and added all those ForeignkeyField
s as FKs do not exist on MyISAM. Wrote a little python views.py, urls.py, few templates...TADACreated https://blocl.uk/schools based on data from https://www.get-information-schools.service.gov.uk/Downloads