In this Short, I demonstrate how to "query" dataframes with Python using the pandas .loc property.
Source code:
Libraries
import pandas as pd
import sqlalchemy
from sqlalchemy import create_engine
Creating SQL Alchemy engine object
engine = create_engine('postgresql://postgres:youtube@localhost:5432/eSports.val')
Initiailizing connection to database
conn = engine.connect()
SQL query as a string to pass into pd.read_sql function
sql = 'SELECT * FROM players'
creating a dataframe
df = pd.read_sql_query(sql,conn)
creating a dataframe where country equals 'us'
USA = df.loc[df['country'] == 'us']
updating the dataframe to encompass countries that contain 'us'
USA = df.loc[df['country'].str.contains('us')]
Sur cette page du site, vous pouvez voir la vidéo en ligne Query pandas dataframes!! durée heure minute seconde en bonne qualité , qui a été Téléchargé par l'utilisateur Data Science with Josh 30 novembre 2022, Partagez le lien avec vos amis et connaissances, sur youtube cette vidéo a déjà été regardée 3,183 fois et il a aimé 103 téléspectateurs. Bon visionnage!