[Python Cookbook] Pandas: 3 Ways to define a DataFrame
Posted Sherrrry
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[Python Cookbook] Pandas: 3 Ways to define a DataFrame相关的知识,希望对你有一定的参考价值。
Using Series (Row-Wise)
import pandas as pd purchase_1 = pd.Series({‘Name‘: ‘Chris‘, ‘Item Purchased‘: ‘Dog Food‘, ‘Cost‘: 22.50}) purchase_2 = pd.Series({‘Name‘: ‘Kevyn‘, ‘Item Purchased‘: ‘Kitty Litter‘, ‘Cost‘: 2.50}) purchase_3 = pd.Series({‘Name‘: ‘Vinod‘, ‘Item Purchased‘: ‘Bird Seed‘, ‘Cost‘: 5.00}) df = pd.DataFrame([purchase_1, purchase_2, purchase_3], index=[‘Store 1‘, ‘Store 1‘, ‘Store 2‘]) df.head()
以上是关于[Python Cookbook] Pandas: 3 Ways to define a DataFrame的主要内容,如果未能解决你的问题,请参考以下文章
[Python Cookbook] Pandas: 3 Ways to define a DataFrame
《Pandas CookBook》---- DataFrame基础操作