LM | Object Data Types |
Object Data Types (Lists, Arrays, DataFrames)
Python offers various complex data types to store collections of data:
- Lists: Ordered, mutable collections of items
- Arrays: More efficient arrays of homogeneous data, often using
numpy
- DataFrames: Tabular data structures from the
pandas
library, ideal for data analysis
Mastering these types allows you to work efficiently with larger and more complex data sets.
Examples
# List example
fruits = ["apple", "banana", "cherry"]
fruits.append("orange")
print(fruits)
# Array example (requires numpy)
import numpy as np
numbers = np.array([1, 2, 3, 4])
print(numbers * 2)
# DataFrame example (requires pandas)
import pandas as pd
data = {
"Name": ["Alice", "Bob", "Charlie"],
"Age": [25, 30, 35]
}
df = pd.DataFrame(data)
print(df)