【338】Pandas.DataFrame
Ref: Pandas Tutorial: DataFrames in Python
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行
二、相关方法:
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的更多相关文章
- 【360】pandas.DataFrame、array、list 之间转换
pandas.DataFrame → array → list values 可以转成 array array.tolist() 可以转成 list >>> c 0 1 2 0 0 ...
- 【笔记】Pandas分类数据详解
[笔记]Pandas分类数据详解 Pandas Pandas分类数据详解|轻松玩转Pandas(5) 参考:Pandas分类数据详解|轻松玩转Pandas(5)
- 【转载】pandas中的循环
原始文章链接: https://towardsdatascience.com/how-to-make-your-pandas-loop-71-803-times-faster-805030df4f06 ...
- 【转】Pandas常见用法总结
关键缩写和包导入 在这个速查手册中,我们使用如下缩写: df:任意的Pandas DataFrame对象 s:任意的Pandas Series对象 raw:行标签 col:列标签 引入响应模块: im ...
- 【转】Pandas学习笔记(四)处理丢失值
Pandas学习笔记系列: Pandas学习笔记(一)基本介绍 Pandas学习笔记(二)选择数据 Pandas学习笔记(三)修改&添加值 Pandas学习笔记(四)处理丢失值 Pandas学 ...
- 【转】Pandas速查手册中文版
本文翻译自文章:Pandas Cheat Sheet - Python for Data Science,同时添加了部分注解. 对于数据科学家,无论是数据分析还是数据挖掘来说,Pandas是一个非常重 ...
- 【pandas】pandas.DataFrame.rename()---重置索引名称
官方文档 github地址 例子: 创建DataFrame ### 导入模块 import numpy as np import pandas as pd import matplotlib.pypl ...
- 【python】pandas & matplotlib 数据处理 绘制曲面图
Python matplotlib模块,是扩展的MATLAB的一个绘图工具库,它可以绘制各种图形 建议安装 Anaconda后使用 ,集成了很多第三库,基本满足大家的需求,下载地址,对应选择pytho ...
- 【学习】pandas 基础介绍说明 【pandas】
本文来源于<利用python进行数据分析>中文版,大家有兴趣可以看原版,入门的东西得脚踏实地哈 1.pandas 数据结构介绍 首先熟悉它的两个主要数据结构,Series 和 DataFr ...
随机推荐
- FineUI与百度地图简单示例 (转帖)
http://www.fineui.com/bbs/forum.php?mod=viewthread&tid=4191&extra=page%3D1 前台代码 <%@ Page ...
- Tomcat 8 中的startup.bat
1. bat文件 批处理文件,在DOS和Windows(任意版本)的系统中,bat文件是可执行文件 2. startup.bat 中涉及的bat语法 2.1 @. echo. echo off @ec ...
- Angular 4 表单校验2
1. 将表单的方法移动到单独的ts文件夹中 2. code export function mobileValidator(control: FormControl): any { const myr ...
- Android免费短信验证
转载请注明住处:http://blog.csdn.net/crazy1235/article/details/41912003 介绍 短信验证功能大家都很熟悉了.在很多地方都能见到,注册新用户或者短息 ...
- BEGIN-2_蓝桥杯_序列求和
问题描述 求1+++...+n的值. 输入格式 输入包括一个整数n. 输出格式 输出一行,包括一个整数,表示1+++...+n的值. 样例输入 样例输出 样例输入 说明:有一些试题会给出多组样例输入输 ...
- bzoj2765 铁人双项比赛
Description 铁人双项比赛是吉林教育学院的一项传统体育项目.该项目比赛由长跑和骑自行车组成,参赛选手必须先完成k公里的长跑,然后完成r公里的骑车,才能到达终点.每个参赛选手所擅长的项目不同, ...
- java实验——将100-300之间的素数输出
public class 实验1 { //将100-300之间的素数输出 /** * @param args */ public static void main(String[] args) { / ...
- js获取数组长度,对象成员个数字、符串字数
文章来源:百度文库 Javascript怎么得到数组长度(也就是数组的元素个数)? Javascript怎么获取对象的成员个数? 你肯定想到了array.length!? 那么我们来测试一下下面这 ...
- TensorFlow函数:tf.FIFOQueue队列
转载:https://blog.csdn.net/akadiao/article/details/78552037 tf.FIFOQueue tf.FIFOQueue继承基类QueueBase. Qu ...
- 关闭浏览器时的友情提醒jQuery写法
$(window).bind('beforeunload', function () { return '您确定退出该页面吗?'; }); 支持以下浏览器(对号表示支持,叉号表示不支持.):