Generate table schema inspecting Excel(CSV) and import data

前端 未结 5 1570
盖世英雄少女心
盖世英雄少女心 2021-01-02 23:19

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 sani

5条回答
  •  渐次进展
    2021-01-02 23:31

    As far as I know, there is no tool that can automate this process (I would love for someone to prove me wrong as I've had this exact problem before). When I did this, I came up with two options:
    (1) Manually create the columns in the db with the appropriate types and then import, or
    (2) Write some kind of filter that could "figure out" what data types the columns should be. I went with the first option mainly because I didn't think I could actually write a program to do the type inference.
    If you do decide to write a type inference tool/conversion, here are a couple of issues you may have to deal with:
    (1) Excel dates are actually stored as the number of days since December 31st, 1899; how does one infer then that a column is dates as opposed to some piece of numerical data (population for example)?
    (2) For text fields, do you just make the columns of type varchar(n) where n is the longest entry in that column, or do you make it an unbounded char field if one of the entries is longer than some upper limit? If so, what's a good upper limit?
    (3) How do you automatically convert a float to a decimal with the correct precision and without loosing any places?
    Obviously, this doesn't mean that you won't be able to (I'm a pretty bad programmer). I hope you do, because it'd be a really useful tool to have.

提交回复
热议问题