# Import the pandas library and assign an alias to it
import pandas as pd
# Create a DataFrame by passing a dictionary to the constructor of pd.DataFrame
account_info = pd.DataFrame({"name": ["Bob", "Mary", "Mita"],
"account": [123846, 123972, 347209],
"balance": [123, 3972, 7209]})
# Access rows data by the key of the column
account_info["name"]
0 Bob 1 Mary 2 Mita Name: name, dtype: object
# Access the whole data in the DataFrame
account_info
name | account | balance | |
---|---|---|---|
0 | Bob | 123846 | 123 |
1 | Mary | 123972 | 3972 |
2 | Mita | 347209 | 7209 |
# Update rows for the column name
account_info["name"] = ["Smith", "Jane", "Patel"]
account_info
name | account | balance | |
---|---|---|---|
0 | Smith | 123846 | 123 |
1 | Jane | 123972 | 3972 |
2 | Patel | 347209 | 7209 |
# Create a sub-DataFrame
account_info[["name", "balance"]]
name | balance | |
---|---|---|
0 | Smith | 123 |
1 | Jane | 3972 |
2 | Patel | 7209 |
account_info
name | account | balance | |
---|---|---|---|
0 | Smith | 123846 | 123 |
1 | Jane | 123972 | 3972 |
2 | Patel | 347209 | 7209 |