感觉很详细:数据分析:pandas 基础

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt dates = pd.date_range('', periods=3) # 创建 16 17 18 等六个日期 df = pd.DataFrame(np.random.randn(3,4), index=dates, columns=list('ABCD')) # 这是二维的,类似于一个表!
# 通过 numpy 随机了一个 3 * 4 的数据,这和行数、列数是相对应的
# print(df)
# A B C D
# 2018-01-16 -0.139759 0.857653 0.754470 0.224313
# 2018-01-17 1.565070 0.521973 -1.265168 -0.278524
# 2018-01-18 -0.668574 -0.527155 0.877785 -1.123334 # print(df.head(1)) # 默认值是 5
# A B C D
# 2018-01-16 -0.039203 1.211976 0.664805 0.307147 df.tail(5) # 同上,顾名思义 # print(df.index) # 顾名思义 + 1
# print(df.columns)
# DatetimeIndex(['2018-01-16', '2018-01-17', '2018-01-18'], dtype='datetime64[ns]', freq='D')
# Index(['A', 'B', 'C', 'D'], dtype='object') # print(df.describe()) # 对每列数据做一些简单的统计学处理
# A B C D
# count 3.000000 3.000000 3.000000 3.000000
# mean -0.163883 -0.107242 -0.621706 0.618341
# std 0.360742 0.429078 0.800366 0.609524
# min -0.505212 -0.502887 -1.352274 0.055032
# 25% -0.352602 -0.335291 -1.049444 0.294803
# 50% -0.199991 -0.167695 -0.746613 0.534574
# 75% 0.006782 0.090581 -0.256421 0.899995
# max 0.213556 0.348857 0.233770 1.265416 # print(df.T) # 转置(Transposing)
# 2018-01-16 2018-01-17 2018-01-18
# A -1.137015 -0.067200 0.737709
# B -1.141811 0.335953 1.023016
# C 2.481266 -0.957599 0.011144
# D 1.485434 -0.605588 0.592746 # print(df)
# print(df.sort_index(axis=1, ascending=False)) # axis=1 按照列名排序 axis=0 按照行名排序
# A B C D
# 2018-01-16 -0.787226 0.321619 1.097938 -0.701082
# 2018-01-17 -0.417257 -0.163390 -0.943166 -0.497475
# 2018-01-18 0.486670 -0.733582 1.923475 -1.145891
# D C B A
# 2018-01-16 -0.701082 1.097938 0.321619 -0.787226
# 2018-01-17 -0.497475 -0.943166 -0.163390 -0.417257
# 2018-01-18 -1.145891 1.923475 -0.733582 0.486670 # print(df.sort_values(by='B'))
# A B C D
# 2018-01-17 0.817088 -0.792903 1.643429 -0.008784
# 2018-01-18 0.540910 0.662119 0.190846 -0.960926
# 2018-01-16 0.333727 1.196133 -0.527796 0.677337

Python笔记 #13# Pandas: Viewing Data的更多相关文章

  1. Python笔记 #15# Pandas: Missing Data

    10 Minutes to pandas import pandas as pd import numpy as np import matplotlib.pyplot as plt dates = ...

  2. Python笔记 #18# Pandas: Grouping

    10 Minutes to pandas 引 By “group by” we are referring to a process involving one or more of the foll ...

  3. Python笔记 #16# Pandas: Operations

    10 Minutes to pandas #Stats # shift 这玩意儿有啥用??? s = pd.Series([1,5,np.nan], index=dates).shift(0) # s ...

  4. Python笔记 #14# Pandas: Selection

    10 Minutes to pandas import pandas as pd import numpy as np import matplotlib.pyplot as plt dates = ...

  5. python笔记-13 mysql与sqlalchemy

    一.RDBMS relational database management system 关系型数据库引入 1.数据库的意义 更有效和合理的存储读取数据的一种方式 关系模型基础上的数据库 -> ...

  6. Python笔记 #17# Pandas: Merge

    10 Minutes to pandas Concat df = pd.DataFrame(np.random.randn(10, 4)) print(df) # break it into piec ...

  7. python笔记13

    今日内容 装饰器 推导式 模块[可选] 内容回顾 函数 参数 def (a1,a2):pass def (a1,a2=None):pass 默认参数推荐用不可变类型,慎用可变类型. def(*args ...

  8. MIT 计算机科学及编程导论 Python 笔记 1

    计算机科学及编程导论在 MIT 的课程编号是 6.00.1,是计算机科学及工程学院的经典课程.之前,课程一直使用 Scheme 作为教学语言,不过由于 Python 简单.易学等原因,近年来已经改用 ...

  9. 13.python笔记之pyyaml模块

    Date:2016-03-25 Title:13.Python笔记之Pyymal模块使用 Tags:Python Category:Python 博客地址:www.liuyao.me 作者:刘耀 YA ...

随机推荐

  1. Lua脚本和C++交互(二)

    上一节讲了一些基本的Lua应用,下面,我要强调一下,Lua的栈的一些概念,因为这个确实很重要,你会经常用到.熟练使用Lua,最重要的就是要时刻知道什么时候栈里面的数据是什么顺序,都是什么.如果你能熟练 ...

  2. jsonObject的一些方法

    1.从前端传过来的数字,默认是Integer类型不能直接用Long接收 错误写法: 报错:Exception in thread "main" java.lang.ClassCas ...

  3. Swift-Swift的Singleton三种写法

    第一种: import Foundation class SingletonA : NSObject { static let sharedInstance: SingletonA = Singlet ...

  4. MQTT-SN协议乱翻之功能描述

    前言 紧接上文,这是第三篇,主要是对MQTT-SN 1.2协议进行总体性功能描述. 嗯,这一部分可以结合着MQTT协议对比着来看. 网关的广播和发现 网关只能在成功连接到MQTT Server之后,才 ...

  5. [SCOI2008] 着色方案[高维dp]

    321. [SCOI2008] 着色方案 ★★★   输入文件:color.in   输出文件:color.out   简单对比时间限制:1 s   内存限制:64 MB 题目背景: 有n个木块排成一 ...

  6. 宝塔面板快速开启https服务

    最近在做小程序开发,急需要一个https的域名,首先我的域名是阿里云的,服务器是腾讯云的,操作都一样: 无论阿里云还是腾讯云,配置SSL是针对服务器的,所以首先是要去申请 腾讯/阿里云服务器的SSL( ...

  7. 设备加速传感器(accelerometer) ---- HTML5+

    模块:Accelerometer Accelerometer模块管理设备加速度传感器,用于获取设备加速度信息,包括x(屏幕水平方向).y(垂直屏幕水平方向).z(垂直屏幕平面方向)三个方向的加速度信息 ...

  8. R的替换sub和gsub

    sub(pattern, replacement, x, ignore.case = FALSE, perl = FALSE, fixed = FALSE, useBytes = FALSE) gsu ...

  9. Redis高级进阶

    目录 本章目标 Redis配置文件 Redis存储 Redis事务 Redis发布订阅 Redis安全 本章目标 Redis配置文件 Redis的存储 Redis的事务 Redis发布订阅 Redis ...

  10. codeforces#512 Div2

    pre过了三题 终测又挂了一题 又掉分了 真的是 太菜了 A-In Search of an Easy Problem 水题 有一个1就是hard #include <bits/stdc++.h ...