How to access a DataFrame column with Pandas
Land Your First Data Science Job
A proven roadmap to prepare for $75K+ entry-level data roles. Perfect for Data Scientist ready to level up their career.
When you will use Pandas DataFrame you certainly will need to access its columns.
Here two ways to access it :
- Using squared brackets
- Using dot
Generating the example DataFrame
# We create our dataframe example
df = pd.DataFrame({"col1":range(0,10)})
# We print it
print(df)
Using squared brackets
Using dot
Be careful with this method since it is not possible to have column names with spaces or weird characters and creating a new column is not possible like this.
Here you are ! You are now an expert at accessing DataFrame columns !
More on DataFrames
If you want to know more about DataFrame and Pandas. Checkout the other articles I wrote on the topic, just here :
Land Your First Data Science Job
A proven roadmap to prepare for $75K+ entry-level data roles. Perfect for Data Scientist ready to level up their career.
Related Articles
Continue your learning journey with these related topics
Master Data Science in Days, Not Months 🚀
Skip the theoretical rabbit holes. Get practical data science skills delivered in bite-sized lessons – Approach used by real data scientist. Not bookworms. 📚