Pandas学习笔记(1)Creating, Reading and Writing

Pandas学习笔记(1)Creating, Reading and Writing,第1张

Pandas学习笔记(1)Creating, Reading and Writing

有两种核心对象一个是Dataframe,一个是Series

1.创建一个如下的叫做fruits的Dataframe:

import pandas as pd
fruits = pd.Dataframe({'Apples':[30],'Bananas':[21]})

2.创建一个如下的叫做fruit_sales的Dataframe:

fruit_sales = pd.Dataframe({'Apples':[35,41],'Bananas':[21,34]},
index = ['2017 Sales','2018 Sales'])

3.用Series创建一个ingredients如下一样:

ingredients = pd.Series(['4 cups','1 cup','2 large','1 can'],
index = ['Flour','Milk','Eggs','Spam'],name = 'Dinner')

4.读../input/wine-reviews/winemag-data_first150k.csv路径下的csv文件为叫做reviews

reviews = pd.read_csv("../input/wine-reviews/winemag-data_first150k.csv",index_col = 0)

5.创建了一个叫做animals的Dataframe将他保存为CSV格式命名为cows_and_goats.csv

animals.to_csv("cows_and_goats.csv")

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5677436.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存