<jupyter_start><jupyter_text>Intro to Dataframes and Basic Selection Creating DataframesPandas loads tabular dataset inside a concept called **DataFrames**. Pandas can read/write dataframes from a variety of formats, making it idealtool to convert file formats in Data Engineering. Dataframes provide an extensive set of built-in functions which allows us to transform and combinedataframes very easily.Let's go through an example together:<jupyter_code>import pandas as pd

df = pd.DataFrame({'apples': [4, 2, 4, 5, 1],
                   'peaches': [1, 7, 4, 6, 5],
                   'eggplants': [1, 3, 1, 3, 0]})
print(df)<jupyter_output><empty_output><jupyter_text>The easiest way to create a DataFrame is to build one from a `dict` where column names are passed as the keys and row values as a `list` for that column. First row of the DataFrame would be the first element of each column list. Accessing Values with BracketsTry accessing values in a DataFrame:<jupyter_code># select a single column
df['apples']
# you can also access as member of DataFrame
df.apples

# accessing values within a column 
df['apples'][0]
df.apples[0]

# access a slice of values
df['apples'][0:4]<jupyter_output><empty_output><jupyter_text>:::info [] access as two dimensional arrayWhen you're using [] to access elements in a DataFrame think of it a a **two dimensional array** where the first domension represents the columns and the second dimenstions represent the row sequence.::: Creating Dataframe with IndexBy default pandas assigns a RangeIndex to the rows starting with 0 (similar to lists). This is what we saw in the exmaples above. However you can specifically assign the **row labels** or **indexes** for each row by index vales:<jupyter_code>df = pd.DataFrame({'apples': [4, 2, 4, 5, 1],
                   'peaches': [1, 7, 4, 6, 5],
                   'eggplants': [1, 3, 1, 3, 0]},
                 index=['A', 'B', 'C', 'D', 'E'])
print(df)<jupyter_output><empty_output><jupyter_text>You can still use brackets to access values:<jupyter_code># you can use both index by position or label
# the correct way would be by label
df['apples']['A']
# or by position
df['apples'][0]

# you can also select multiple rows
df['apples'][['A', 'E', 'D']]<jupyter_output><empty_output><jupyter_text>Assigning ValuesAs easy as reading values, you can also assign values:<jupyter_code># assign a single value
df['apples']['A'] = 10

# assign and add an entire column
df['oranges'] = 0
df['oranges']['D'] = 2

# add an entire row. you will leanr .loc later
df.loc['F'] = {'apples': 3, 'peaches': 0, 'eggplants': 3, 'oranges': 1}

print(df)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11169612636329447, 'fraction_numerical': 0.016547574276043624, 'mean_word_length': 4.553235908141962, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, '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': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '621572', 'license': 'Apache-2.0', 'n_tokens_mistral': 864, 'n_tokens_neox': 805, 'n_words': 345, 'path': 'deb/ch1/pandas-intro/notebooks/01_intro.ipynb', 'repo_name': 'turalabs/deb', 'size': '2659'}