<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Introduction
The first step in most data analytics projects is reading the data file. In this exercise, you'll create Series and DataFrame objects, both by hand and by reading data files.
Run the code cell below to load libraries you will need (including code to check your answers).
Step1:  Exercises
1.
In the cell below, create a DataFrame fruits that looks like this
Step2:  2.
Create a dataframe fruit_sales that matches the diagram below
Step3:  3.
Create a variable ingredients with a Series that looks like
Step5:  4.
Read the following csv dataset of wine reviews into a DataFrame called reviews
Step6:  5.
Run the cell below to create and display a DataFrame called animals
Step7:  In the cell below, write code to save this DataFrame to disk as a csv file with the name cows_and_goats.csv.
<ASSISTANT_TASK:>
Python Code:
import pandas as pd
pd.set_option('max_rows', 5)
from learntools.core import binder; binder.bind(globals())
from learntools.pandas.creating_reading_and_writing import *
print("Setup complete.")
Explanation: Introduction
The first step in most data analytics projects is reading the data file. In this exercise, you'll create Series and DataFrame objects, both by hand and by reading data files.
Run the code cell below to load libraries you will need (including code to check your answers).
End of explanation
# Your code goes here. Create a dataframe matching the above diagram and assign it to the variable fruits.
fruits = ____
# Check your answer
q1.check()
fruits
#%%RM_IF(PROD)%%
dat = [[30, 21]]
cols = ['Apples', 'Bananas']
fruits = pd.DataFrame(dat, columns=cols)
q1.assert_check_passed()
#%%RM_IF(PROD)%%
fruits = pd.DataFrame({'Apples': [30], 'Bananas': [21]})
q1.assert_check_passed()
#%%RM_IF(PROD)%%
fruits = pd.DataFrame({'Apples': [30.], 'Bananas': [21.]})
q1.assert_check_failed()
#%%RM_IF(PROD)%%
fruits = pd.DataFrame({'Apples': [30], 'bananas': [21]})
q1.assert_check_failed()
#_COMMENT_IF(PROD)_
q1.hint()
#_COMMENT_IF(PROD)_
q1.solution()
Explanation: Exercises
1.
In the cell below, create a DataFrame fruits that looks like this:
End of explanation
# Your code goes here. Create a dataframe matching the above diagram and assign it to the variable fruit_sales.
fruit_sales = ____
# Check your answer
q2.check()
fruit_sales
#%%RM_IF(PROD)%%
fruit_sales = pd.DataFrame([[35, 21], [41, 34]], columns=['Apples', 'Bananas'],
                index=['2017 Sales', '2018 Sales'])
q2.assert_check_passed()
#%%RM_IF(PROD)%%
fruit_sales = pd.DataFrame([[35, 21], [41, 34]][::-1], columns=['Apples', 'Bananas'],
                index=['2017 Sales', '2018 Sales'])
q2.assert_check_failed()
#_COMMENT_IF(PROD)_
q2.hint()
#_COMMENT_IF(PROD)_
q2.solution()
Explanation: 2.
Create a dataframe fruit_sales that matches the diagram below:
End of explanation
ingredients = ____
# Check your answer
q3.check()
ingredients
#%%RM_IF(PROD)%%
quantities = ['4 cups', '1 cup', '2 large', '1 can']
items = ['Flour', 'Milk', 'Eggs', 'Spam']
ingredients = pd.Series(quantities, index=items, name='Dinner')
q3.assert_check_passed()
#%%RM_IF(PROD)%%
quantities = ['4 cups', '1 cup', '2 large', '1 can']
items = ['Flour', 'Milk', 'Eggs', 'Spam']
ingredients = pd.Series(quantities, index=items)
q3.assert_check_failed()
#%%RM_IF(PROD)%%
quantities = ['4 cups', '1 cup', '2 large', '1 can'][::-1]
items = ['Flour', 'Milk', 'Eggs', 'Spam'][::-1]
ingredients = pd.Series(quantities, index=items, name='Dinner')
q3.assert_check_failed()
#_COMMENT_IF(PROD)_
q3.hint()
#_COMMENT_IF(PROD)_
q3.solution()
Explanation: 3.
Create a variable ingredients with a Series that looks like:
Flour     4 cups
Milk       1 cup
Eggs     2 large
Spam       1 can
Name: Dinner, dtype: object
End of explanation
reviews = ____
# Check your answer
q4.check()
reviews
#%%RM_IF(PROD)%%
reviews = pd.read_csv('../input/wine-reviews/winemag-data_first150k.csv', index_col=0)
q4.assert_check_passed()
#%%RM_IF(PROD)%%
reviews = pd.read_csv('../input/wine-reviews/winemag-data_first150k.csv')
q4.assert_check_failed()
#_COMMENT_IF(PROD)_
q4.hint()
#_COMMENT_IF(PROD)_
q4.solution()
#%%RM_IF(PROD)%%
import os
def cleanup_ungulates():
    Function for cleaning up file system state between tests.
    try:
        os.remove('cows_and_goats.csv')
    except FileNotFoundError:
        pass
cleanup_ungulates()
Explanation: 4.
Read the following csv dataset of wine reviews into a DataFrame called reviews:
The filepath to the csv file is ../input/wine-reviews/winemag-data_first150k.csv. The first few lines look like:
,country,description,designation,points,price,province,region_1,region_2,variety,winery
0,US,"This tremendous 100% varietal wine[...]",Martha's Vineyard,96,235.0,California,Napa Valley,Napa,Cabernet Sauvignon,Heitz
1,Spain,"Ripe aromas of fig, blackberry and[...]",Carodorum Selección Especial Reserva,96,110.0,Northern Spain,Toro,,Tinta de Toro,Bodega Carmen Rodríguez
End of explanation
animals = pd.DataFrame({'Cows': [12, 20], 'Goats': [22, 19]}, index=['Year 1', 'Year 2'])
animals
Explanation: 5.
Run the cell below to create and display a DataFrame called animals:
End of explanation
# Your code goes here
# Check your answer
q5.check()
#%%RM_IF(PROD)%%
animals.to_csv("cows_and_goats.csv")
q5.assert_check_passed()
cleanup_ungulates()
#%%RM_IF(PROD)%%
animals.to_csv("cows_and_goats.csv", index=False)
q5.assert_check_failed()
cleanup_ungulates()
#_COMMENT_IF(PROD)_
q5.hint()
#_COMMENT_IF(PROD)_
q5.solution()
Explanation: In the cell below, write code to save this DataFrame to disk as a csv file with the name cows_and_goats.csv.
End of explanation
<END_TASK>