import pandas as pd
pd.set_option('max_rows', 5)
from learntools.core import binder.bind(globals())
from learntools.pandas.creating_reading_and_writing import *
print("Setup complete")
1번째 방법
fruits = pd.DataFrame([[30, 21]], columns = ['Apples', 'Bananas'])
2번째 방법
fruits = pd.DataFrame({'Apples':[30], 'Bananas':[21]})
1번째 방법
fruit_sales = pd.DataFrame([[35, 32], [41, 34]], index = ['2017 Sales', '2018 Sales'], columns = ['Apples', 'Bananas'])
2번째 방법
fruit_sales = pd.DataFrame({'Apples': [35, 41], 'Bananas' : [21, 34]}, index = ['2017 Sales', '2018 Sales'])
Flour 4 cups
Milk 1 cup
Eggs 2 large
Spam 1 can
Name: Dinner, dtype: object
1번째 방법
ingredients = pd.Series(['4 cups', '1 cup', '2 large', '1 can'], index = ['Flour', 'Milk', 'Eggs', 'Spam'], name = 'Dinner')
2번째 방법
measurement = ['4 cups', '1 cup', '2 large', '1 can']
food = ['Flour', 'Milk', 'Eggs', 'Spam']
ingredients = pd.Series(measurement, index = food, name='Dinner')
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
reviews = pd.read_csv('../input/wine-reviews/winemag-data_first150k.csv', index_col = 0)
animals = pd.DataFrame({'Cows' : [12, 20], 'Goats': [22, 19]}, index=['Year 1', 'Year2'])
animals
In the cell below, write code to save this DataFrame to disk as a csv file with the name cows_and_goats.csv
.
animals.to_csv('cows_and_goats.csv', header=True)