该博客是Pandas课程习题,前往此处可学习课程
习题
1.
创建一个和下图一样的DataFrame fruits
提示
提示:`pd.DataFrame`语句来创建一个DataFrameCode
fruits = pd.DataFrame({'Apples': [30], 'Bananas': [21]})
2.
创建一个和下图一样的DataFramefruit_sales
Code
fruit_sales = pd.DataFrame({'Apples': [35, 41], 'Bananas': [21, 34]}, index=['2017 Sales', '2018 Sales'])
3.
创建一个和下表相同的Seriesingredients
Flour 4 cups
Milk 1 cup
Eggs 2 large
Spam 1 can
Name: Dinner, dtype: object
Code
ingredients = pd.Series({'Flour': '4 cups', 'Milk': '1 cup', 'Eggs': '2 large', 'Spam': '1 can'}, name='Dinner')
4.
将下列红酒评测数据集读取到DataFrame中并命名为reviews
点击此处链接下载数据集
Code
reviews = pd.read_csv('../input/wine-reviews/winemag-data_first150k.csv', index_col=0)
5.
运行下列代码,创建并展示一个叫做animals
的DataFrame
animals = pd.DataFrame({'Cows': [12, 20], 'Goats': [22, 19]}, index=['Year 1', 'Year 2'])
animals
写出一段代码将该DataFrame存到本地,并将其命名为cows_and_goats.csv
Code
animals.to_csv('cows_and_goats.csv')