<jupyter_start><jupyter_text>you saw that you can index and select Pandas DataFrames in many different ways. The simplest, but not the most powerful way, is to use square brackets.In the sample code on the right, the same cars data is imported from a CSV files as a Pandas DataFrame. To select only the cars_per_cap column from cars, you can use:>cars['cars_per_cap']>cars[['cars_per_cap']]The single bracket version gives a Pandas Series, the double bracket version gives a Pandas DataFrame.<jupyter_code># Import cars data
import pandas as pd
cars = pd.read_csv('cars.csv', index_col = 0)<jupyter_output><empty_output><jupyter_text>Use single square brackets to print out the country column of cars as a Pandas Series.<jupyter_code># Print out country column as Pandas Series
print(cars['country'])<jupyter_output>US     United States
AUS        Australia
JAP            Japan
IN             India
RU            Russia
MOR          Morocco
EG             Egypt
Name: country, dtype: object<jupyter_text>Use double square brackets to print out the country column of cars as a Pandas DataFrame.<jupyter_code># Print out country column as Pandas DataFrame
print(cars[['country']])<jupyter_output>country
US   United States
AUS      Australia
JAP          Japan
IN           India
RU          Russia
MOR        Morocco
EG           Egypt<jupyter_text>Use double square brackets to print out a DataFrame with both the country and drives_right columns of cars, in this order.<jupyter_code># Print out DataFrame with country and drives_right columns
print(cars[['country','drives_right']])<jupyter_output>country  drives_right
US   United States          True
AUS      Australia         False
JAP          Japan         False
IN           India         False
RU          Russia          True
MOR        Morocco          True
EG           Egypt          True
{'fraction_non_alphanumeric': 0.05129589632829374, 'fraction_numerical': 0.0005399568034557236, 'mean_word_length': 3.0547045951859957, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '530430', 'license': 'MIT', 'n_tokens_mistral': 531, 'n_tokens_neox': 499, 'n_words': 215, 'path': 'Intermediate Python for Data Science/Dictionaries - Pandas/08-Square Brackets (1).ipynb', 'repo_name': 'nazmusshakib121/Python-Programming', 'size': '1852'}