Pandas — DataFrames
Create DataFrame
import pandas as pd
# From dictionary
df = pd.DataFrame({
'name': ['Alice', 'Bob', 'Charlie'],
'age': [25, 30, 35],
'city': ['NYC', 'LA', 'Chicago']
})
# From list of lists
df = pd.DataFrame([['Alice', 25], ['Bob', 30]], columns=['name', 'age'])
Basic info
print(df.head()) # First 5 rows
print(df.shape) # (rows, cols)
print(df.columns) # Column names
print(df.dtypes) # Data types
print(df.info()) # Summary
print(df.describe()) # Statistics
Selection
# Select column
df['name']
# Select multiple columns
df[['name', 'age']]
# Select row by label
df.loc[0]
# Select row by position
df.iloc[0]
Mini Practice
- Create DataFrame
- View basic info
- Select columns
- Use loc and iloc
Up Next
Continue with CSV - Reading/writing CSV files.
Related Topics
Frequently Asked Questions about DataFrames
What is DataFrames in Pandas?
DataFrames is a fundamental concept in Pandas. This lesson explains it step by step with clear examples, making it easy for beginners to understand.
How do I learn DataFrames?
Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn DataFrames.
Why is DataFrames important in Pandas?
DataFrames is essential for Pandas development. Understanding this concept will help you write better code and solve real-world problems more effectively.