Ref: Pandas Tutorial: DataFrames in Python

Ref: pandas.DataFrame

Ref: Pandas:DataFrame对象的基础操作


Ref: Creating, reading, and writing reference

  • pandas.DataFrame()
  • pandas.Series()
  • pandas.read_csv()
  • pandas.DataFrame.shape
  • pandas.DataFrame.head
  • pandas.read_excel()
  • pandas.to_csv()
  • pandas.to_excel()

Ref: Indexing, selecting, assigning reference

  • pandas.iloc(): 类似于Excel中的Cell函数,将其看做Matrix
  • pandas.loc()

一、基本概念

class pandas.DataFrame(data=None, index=None, columns=None, dtype=None, copy=False)
Parameters:

data : 数据主体部分,numpy ndarray (structured or homogeneous), dict, or DataFrame

Dict can contain Series, arrays, constants, or list-like objects

Changed in version 0.23.0: If data is a dict, argument order is maintained for Python 3.6 and later.

index : 行名称,默认 0, 1, 2, ..., n, Index or array-like

Index to use for resulting frame. Will default to RangeIndex if no indexing information part of input data and no index provided

columns : 列名称,默认 0, 1, 2, ..., n, Index or array-like

Column labels to use for resulting frame. Will default to RangeIndex (0, 1, 2, …, n) if no column labels are provided

dtype : 数据类型,dtype, default None

Data type to force. Only a single dtype is allowed. If None, infer

copy : boolean, default False

Copy data from inputs. Only affects DataFrame / 2d ndarray input

data[1:,0] means the first column, data[0,1:] means the first row.

>>> import numpy as np
>>> import pandas as pd
>>> data = np.array([
['','Col1','Col2'],
['Row1',1,2],
['Row2',3,4]
])
>>> print(pd.DataFrame(data=data[1:,1:],
index=data[1:,0],
columns=data[0,1:]))
Col1 Col2
Row1 1 2
Row2 3 4

or

>>> data = np.array([
[1,2],
[3,4]])
>>> print(pd.DataFrame(data=data,
index=['Row1','Row2'],
columns=['Col1','Col2']))
Col1 Col2
Row1 1 2
Row2 3 4

Ref: pandas dataframe.apply() 实现对某一行/列进行处理获得一个新行/新列

Ref: 在pandas中遍历DataFrame行

Ref: pandas.DataFrame.apply


二、相关方法:

DataFrame.apply(func, axis=0, broadcast=None, raw=False, reduce=None, result_type=None, args=(), **kwds)

Apply a funciton along an axis of the DataFrame. (类似Excel中对一列或者一行数据进行摸个函数的处理)

Objects passed to the function are Series objects whose index is either the DataFrame's index (axis=0) or the DataFrame's columns (axis=1).

Ref: pandas.Series.value_counts

Series.value_counts(normalize=False, sort=True, ascending=False, bins=None, dropna=True)

Returns object containing counts of unique values.

The resulting object will be in desceding order so that the first element is the most frequent-occurring element. Excludes NA values by default.

DataFrame.read_csv():  可以将 Str 通过 StringIO() 转为文件缓存,可以直接用此方法

>>> from io import StringIO
>>> a = '''
A, B, C
1,2,3
4,5,6
7,8,9
'''
>>> a
'\nA, B, C\n1,2,3\n4,5,6\n7,8,9\n'
>>> data = pd.read_csv(StringIO(a))
>>> data
A B C
0 1 2 3
1 4 5 6
2 7 8 9

【338】Pandas.DataFrame的更多相关文章

  1. 【360】pandas.DataFrame、array、list 之间转换

    pandas.DataFrame → array → list values 可以转成 array array.tolist() 可以转成 list >>> c 0 1 2 0 0 ...

  2. 【笔记】Pandas分类数据详解

    [笔记]Pandas分类数据详解 Pandas  Pandas分类数据详解|轻松玩转Pandas(5) 参考:Pandas分类数据详解|轻松玩转Pandas(5)

  3. 【转载】pandas中的循环

    原始文章链接: https://towardsdatascience.com/how-to-make-your-pandas-loop-71-803-times-faster-805030df4f06 ...

  4. 【转】Pandas常见用法总结

    关键缩写和包导入 在这个速查手册中,我们使用如下缩写: df:任意的Pandas DataFrame对象 s:任意的Pandas Series对象 raw:行标签 col:列标签 引入响应模块: im ...

  5. 【转】Pandas学习笔记(四)处理丢失值

    Pandas学习笔记系列: Pandas学习笔记(一)基本介绍 Pandas学习笔记(二)选择数据 Pandas学习笔记(三)修改&添加值 Pandas学习笔记(四)处理丢失值 Pandas学 ...

  6. 【转】Pandas速查手册中文版

    本文翻译自文章:Pandas Cheat Sheet - Python for Data Science,同时添加了部分注解. 对于数据科学家,无论是数据分析还是数据挖掘来说,Pandas是一个非常重 ...

  7. 【pandas】pandas.DataFrame.rename()---重置索引名称

    官方文档 github地址 例子: 创建DataFrame ### 导入模块 import numpy as np import pandas as pd import matplotlib.pypl ...

  8. 【python】pandas & matplotlib 数据处理 绘制曲面图

    Python matplotlib模块,是扩展的MATLAB的一个绘图工具库,它可以绘制各种图形 建议安装 Anaconda后使用 ,集成了很多第三库,基本满足大家的需求,下载地址,对应选择pytho ...

  9. 【学习】pandas 基础介绍说明 【pandas】

    本文来源于<利用python进行数据分析>中文版,大家有兴趣可以看原版,入门的东西得脚踏实地哈 1.pandas 数据结构介绍 首先熟悉它的两个主要数据结构,Series 和 DataFr ...

随机推荐

  1. AngularJS---核心特性

    步入正题.学习Angular,首先得了解.熟知.掌握它的四大核心特性. 一.MVC模式 Model(模型):是应用程序中用于处理应用程序数据逻辑的部分,通常模型对象负责在数据库中存取数据. View( ...

  2. spring boot学习(2) SpringBoot 项目属性配置

    第一节:项目内置属性 application.properties配置整个项目的,相当于以前的web.xml: 注意到上一节的访问HelloWorld时,项目路径也没有加:直接是http://loca ...

  3. ApplicationEvent事件机制源码分析

    <spring扩展点之三:Spring 的监听事件 ApplicationListener 和 ApplicationEvent 用法,在spring启动后做些事情> <服务网关zu ...

  4. AspectJ入门

    AOP的实现方式有两种: AOP框架在编译阶段,就对目标类进行修改,得到的class文件已经是被修改过的.生成静态的AOP代理类(生成*.class文件已经被改掉了,需要使用特定的编译器).以Aspe ...

  5. 关于java.lang.IncompatibleClassChangeError: Implementing class错误解决

    在javaagent使用asm字节码编程的时候启动异常,java.lang.IncompatibleClassChangeError: Implementing class, 这是包冲突引起的问题,加 ...

  6. OSPF两种组播地址的区别和联系

    1.点到点网络: 是连接单独的一对路由器的网络,点到点网络上的有效邻居总是可以形成邻接关系的,在这种网络上,OSPF包的目标地址使用的是224.0.0.52.广播型网络, 比如以太网,Token Ri ...

  7. JQUERY dialog的用法详细解析

    本篇文章主要是对JQUERY中dialog的用法进行了详细的分析介绍,需要的朋友可以过来参考下,希望对大家有所帮助 今天用到了客户端的对话框,把 jQuery UI 中的对话框学习了一下. 准备 jQ ...

  8. js如何判断小数点后有几位

    <script> var n=3.143423423;alert(n.toString().split(".")[1].length); </script> ...

  9. Z-tree 统计每一父节点的叶子节点数(看这一篇就够了)

    最近刚走出校园的我找到了第一份工作,在入职考核中就遇见了一道Z-tree的试题 这道题目本身是不难的,但是我第一次接触这个插件而且还把解决问题的方向搞错了,弄的我好几天都很难受. 弄得我都开始怀疑人生 ...

  10. 基于WMI获取本机真实网卡物理地址和IP地址

    using System; using System.Collections.Generic; using System.Management; using System.Runtime.Intero ...