Instead, we might save the qeury results to a newĭatabase that is more appropriate for downstream work. However, we might avoid doing this if the database is anĪuthoritative source (potentially version controlled) which should notīe modified by users. Instead of performing the query themselves, particularly if it is Potentially data corrections) are likely to be required by many it mayīe efficient for one person to perform the work and save it back to theĭatabase as a new table so others can access the results directly If the database is shared with others and common queries (and connect( "data/portal_mammals.sqlite") # Read the results into a DataFrame df1 = pd.read_sql_query( 'SELECT surveys.year,ot_type,species.genus,species.species,x \ FROM surveys INNER JOIN plots ON ot = ot_id INNER JOIN species ON \ surveys.species = species.species_id WHERE surveys.year>=1998 AND surveys.year<=2001 \ AND ( x = "M" OR x = "F")') df1.to_sql( "New Table 1", con, if_exists = "replace") # We already have the 'df' DataFrame created in the earlier exercise df.to_sql( "New Table 2", con, if_exists = "replace") # Close the connection con.close() PYTHON #Connect to the database con = sqlite3. Those survey results for 2002, and then save it out to its own table so We first read in our survey data, then select only Here, we re-do an exercise we did before with CSV files using ![]() ![]() We can also use pandas to create new tables within an SQLiteĭatabase. Storing data: Create new tables using Pandas We will create relationships between tables and learn how to add and re.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |