Last active
August 29, 2015 14:06
-
-
Save lucidfrontier45/4414d0e270565d4a2298 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import sqlalchemy | |
from sklearn import datasets | |
# create iris dataframe | |
iris = datasets.load_iris() | |
iris_data = pd.DataFrame(iris.data) | |
iris_data.columns = ["sep_length", "sepal_width","petal_length","petal_width" ] | |
iris_data["species"] = map(lambda i:iris.target_names[i], iris.target) | |
#insert into sqlite | |
engine = sqlalchemy.create_engine("sqlite:///test_db") | |
iris_data.to_sql("iris_dat", engine, index=False, if_exists="replace") | |
# insert into postgresql | |
engine = sqlalchemy.create_engine("postgresql://<user>:<passwd>@localhost/test_db") | |
iris_data.to_sql("iris_dat", engine, index=False, if_exists="replace") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment