df
variable which is an instance of thepandas DataFrameclass.count
function on this DataFrame, we get back that ithas 7320 rows.countriesAndTerritories
columnto the country of our choice.save_df
variable contains the smaller subset of data. You canfind out what's in it by having it print itself:save_pandas.db
. You can of course save the file with whatever nameyou want and in any location, not just the directory where you areexecuting the Python REPL.create_engine
function from the sqlalchemy
library.create_engine
functionand then invoking the connect
method on it.echo=True
to see all of the output that comes from ourdatabase connection. When the connection is successful you willsee output similar to the following:to_sql
method on the save_df
object, which is our pandas DataFrame thatis a subset of the original data set with 89 rows filtered fromthe original 7320.if_exists
to to replace
or append
and add your own exception handling in a more robustversion of this program. Check thepandas.DataFrame.to_sqldocumentation for the extensive details on your options.sqlite3
Movist pro 2 1 38. command line viewerto make sure it was properly saved to the SQLite file.save_pandas.db
file..open
command with our save_pandas.db
file name toaccess the database. Then use a standard SQL query to obtain allof the records from the Covid19
table.countriesAndTerritories
column matchingUnited_States_of_America
is there! We successfully exported thedata from the DataFrame into the SQLite database file.