<jupyter_start><jupyter_text>Creating Reading & Writing------  Tutorial--- **Getting started** To use pandas, you'll typically start with the following line of code.<jupyter_code>import pandas as pd<jupyter_output><empty_output><jupyter_text>Creating dataThere are two core objects in pandas: the **DataFrame** and the **Series**. A **DataFrame** is a table. It contains an array of individual *entries*, each of which has a certain *value*. Each entry corresponds to *row* and *column*. The pd.DataFrame() constructor to generate DataFrame objects. The syntax for declaring a new one is a dictionary whose keys are the column names, and whose values are a list of entries.<jupyter_code>pd.DataFrame({'Yes': [50, 21], 'No': [131, 2]})
pd.DataFrame({'Bob': ['I liked it.', 'It was awful.'], 'Sue': ['Pretty good.', 'Bland.']})<jupyter_output><empty_output><jupyter_text>The dictionary-list constructor assigns values to the *column labels*, but just uses an ascending count from 0 for the *row labels*. The list of row labels used in a DataFrame is known as an **Index**. We can assign values to it by using an `index` parameter in our constructor:<jupyter_code>pd.DataFrame({'Bob': ['I liked it.', 'It was awful.'], 
              'Sue': ['Pretty good.', 'Bland.']},
             index=['Product A', 'Product B'])<jupyter_output><empty_output><jupyter_text>A **Series**, by contrast, is a sequence of data values. If a DataFrame is a table, a Series is a list. And in fact you can create one with nothing more than a list. A Series is, in essence, a single column of a DataFrame. So you can assign column values to the Series the same way as before, using an `index` parameter. However, a Series does not have a column name, it only has one overall `name`.<jupyter_code>pd.Series([1, 2, 3, 4, 5])
pd.Series([30, 35, 40], index=['2015 Sales', '2016 Sales', '2017 Sales'], name='Product A')
# Dataset are available in google drive
from google.colab import drive
drive.mount('/content/gdrive')

# Mounded the drive now we can acces the data from its location<jupyter_output>Mounted at /content/gdrive<jupyter_text>Reading data filesData can be stored in any of a number of different forms and formats. By far the most basic of these is the humble CSV file. we can use the `pd.read_csv()` function to read the data into a DataFrame.<jupyter_code>wine_reviews = pd.read_csv("/content/gdrive/MyDrive/Colab Notebooks/Kaggle_Courses/02 Pandas/winemag-data-130k-v2.csv")
wine_reviews.shape
wine_reviews.head()<jupyter_output><empty_output><jupyter_text>The `pd.read_csv()` function is well-endowed, with over 30 optional parameters you can specify. To make pandas use that column for the index (instead of creating a new one from scratch), we can specify an `index_col`.<jupyter_code>wine_reviews = pd.read_csv("/content/gdrive/MyDrive/Colab Notebooks/Kaggle_Courses/02 Pandas/winemag-data-130k-v2.csv", index_col=0)
wine_reviews.head()<jupyter_output><empty_output><jupyter_text>Exercise--- In the cell below, create a DataFrame `fruits` that looks like this:![](https://i.imgur.com/Ax3pp2A.png)<jupyter_code># Your code goes here. Create a dataframe matching the above diagram and assign it to the variable fruits.
fruits = pd.DataFrame({'Apples': [30], 'Bananas': [21]})
fruits<jupyter_output><empty_output><jupyter_text>Create a dataframe `fruit_sales` that matches the diagram below:![](https://i.imgur.com/CHPn7ZF.png)<jupyter_code># Your code goes here. Create a dataframe matching the above diagram and assign it to the variable fruit_sales.
fruit_sales = pd.DataFrame({'Apples': [35,41], 
              'Bananas': [21, 34]},
             index=['2017 Sales', '2018 Sales'])

fruit_sales<jupyter_output><empty_output><jupyter_text>Create a variable `ingredients` with a Series that looks like:```Flour     4 cupsMilk       1 cupEggs     2 largeSpam       1 canName: Dinner, dtype: object```<jupyter_code>wine_reviews = pd.read_csv("/content/gdrive/MyDrive/Colab Notebooks/Kaggle_Courses/02 Pandas/winemag-data-130k-v2.csv", index_col=0)<jupyter_output><empty_output><jupyter_text>Run the cell below to create and display a DataFrame called animals. In the cell below, write code to save this DataFrame to disk as a csv file with the name `cows_and_goats.csv`.<jupyter_code>animals = pd.DataFrame({'Cows': [12, 20], 'Goats': [22, 19]}, index=['Year 1', 'Year 2'])
animals
# Your code goes here
animals.to_csv("cows_and_goats.csv")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11641991924629878, 'fraction_numerical': 0.02041274113952445, 'mean_word_length': 5.184466019417476, 'pattern_counts': {'":': 0, '<': 40, '<?xml version=': 0, '>': 40, 'https://': 2, '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': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '278496', 'license': 'Apache-2.0', 'n_tokens_mistral': 1507, 'n_tokens_neox': 1389, 'n_words': 513, 'path': '02 Pandas/01 Creating Reading & Writing.ipynb', 'repo_name': 'Bluelord/Kaggle_Courses', 'size': '4458'}