[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()

原文地址:https://www.cnblogs.com/sherrydatascience/p/10336571.html

时间: 2024-08-12 18:04:43

[Python Cookbook] Pandas: 3 Ways to define a DataFrame的相关文章

[Python Cookbook] Pandas Groupby

Groupby Count # Party's Frequency of donations nyc.groupby('Party')['contb receipt amt'].count() The command returns a series where the index is the name of a Party and the value is the count of that Party. Note that the series is ordered by the name

[Python Cookbook] Pandas: Indexing of DataFrame

Selecting a Row df.loc[index] # if index is a string, add ' '; if index is a number, no ' ' or df.iloc[row_num] Selecting a Column df['col_name'] Or df.col_name Selecting an Element df.loc[index, 'col_name'] Selecting Multiple Discontinuous Rows df.l

《Python cookbook》 “定义一个属性可由用户修改的装饰器” 笔记

看<Python cookbook>的时候,第9.5部分,"定义一个属性可由用户修改的装饰器",有个装饰器理解起来花了一些时间,做个笔记免得二刷这本书的时候忘了 完整代码:https://github.com/blackmatrix7/python-learning/blob/master/python_cookbook/chapter_9/section_5/attach_wrapper.py 书中的装饰器(书中称之为访问器函数) def attach_wrapper(o

3 ways to define a JavaScript class

3 ways to define a JavaScript class September 29th, 2006. Tagged: JavaScript Introduction JavaScript is a very flexible object-oriented language when it comes to syntax. In this article you can find three ways of defining and instantiating an object.

分享一个python cookbook的在线教程地址

分享一个python cookbook的在线教程地址: http://python3-cookbook.readthedocs.org/zh_CN/latest/ 翻译者:熊能

python cookbook —— Searching and Replacing Text in a File

要将文件中的某一个字符串替换为另一个,然后写入一个新文件中: 首先判断输入格式,至少需要输入被搜索的Text和替换的Text,输入输出文件可以是存在的文件,也可以是标准输入输出流 (os.path是个好东西) import os, sys nargs = len(sys.argv) if not 3 <= nargs <= 5: print "usage: %s search_text replace_text [infile [outfile]]" % os.path.b

python之pandas简单介绍及使用(一)

一. Pandas简介 1.Python Data Analysis Library 或 pandas 是基于NumPy 的一种工具,该工具是为了解决数据分析任务而创建的.Pandas 纳入了大量库和一些标准的数据模型,提供了高效地操作大型数据集所需的工具.pandas提供了大量能使我们快速便捷地处理数据的函数和方法.你很快就会发现,它是使Python成为强大而高效的数据分析环境的重要因素之一. 2.Pandas 是python的一个数据分析包,最初由AQR Capital Management

Python Cookbook(第3版)中文版pdf

下载地址:网盘下载 内容简介  · · · · · · <Python Cookbook(第3版)中文版>介绍了Python应用在各个领域中的一些使用技巧和方法,其主题涵盖了数据结构和算法,字符串和文本,数字.日期和时间,迭代器和生成器,文件和I/O,数据编码与处理,函数,类与对象,元编程,模块和包,网络和Web编程,并发,实用脚本和系统管理,测试.调试以及异常,C语言扩展等. 本书覆盖了Python应用中的很多常见问题,并提出了通用的解决方案.书中包含了大量实用的编程技巧和示例代码,并在Py

Python数据分析--Pandas知识点(二)

本文主要是总结学习pandas过程中用到的函数和方法, 在此记录, 防止遗忘. Python数据分析--Pandas知识点(一) 下面将是在知识点一的基础上继续总结. 13. 简单计算 新建一个数据表df 1 import pandas as pd 2 3 df = pd.DataFrame({"地区": ["A区","B区", "C区"], 4 "前半年销量": [3500, 4500,3800], 5