In this Short, I demonstrate how to rename Pandas dataframe columns using the pd.rename function.
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 maps"
creating a dataframe
df = pd.read_sql_query(sql,conn)
renaming columns
df = df.rename(columns={'winrate_atk': 'Win Rate Attack', 'winrate_def': 'Win Rate Defense'})
On this page of the site you can watch the video online Renaming Dataframe Columns with a duration of hours minute second in good quality, which was uploaded by the user Data Science with Josh 28 November 2022, share the link with friends and acquaintances, this video has already been watched 770 times on youtube and it was liked by 27 viewers. Enjoy your viewing!