Python笔记 #13# Pandas: Viewing Data
感觉很详细:数据分析: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的更多相关文章
- Python笔记 #15# Pandas: Missing Data
10 Minutes to pandas import pandas as pd import numpy as np import matplotlib.pyplot as plt dates = ...
- Python笔记 #18# Pandas: Grouping
10 Minutes to pandas 引 By “group by” we are referring to a process involving one or more of the foll ...
- Python笔记 #16# Pandas: Operations
10 Minutes to pandas #Stats # shift 这玩意儿有啥用??? s = pd.Series([1,5,np.nan], index=dates).shift(0) # s ...
- Python笔记 #14# Pandas: Selection
10 Minutes to pandas import pandas as pd import numpy as np import matplotlib.pyplot as plt dates = ...
- python笔记-13 mysql与sqlalchemy
一.RDBMS relational database management system 关系型数据库引入 1.数据库的意义 更有效和合理的存储读取数据的一种方式 关系模型基础上的数据库 -> ...
- Python笔记 #17# Pandas: Merge
10 Minutes to pandas Concat df = pd.DataFrame(np.random.randn(10, 4)) print(df) # break it into piec ...
- python笔记13
今日内容 装饰器 推导式 模块[可选] 内容回顾 函数 参数 def (a1,a2):pass def (a1,a2=None):pass 默认参数推荐用不可变类型,慎用可变类型. def(*args ...
- MIT 计算机科学及编程导论 Python 笔记 1
计算机科学及编程导论在 MIT 的课程编号是 6.00.1,是计算机科学及工程学院的经典课程.之前,课程一直使用 Scheme 作为教学语言,不过由于 Python 简单.易学等原因,近年来已经改用 ...
- 13.python笔记之pyyaml模块
Date:2016-03-25 Title:13.Python笔记之Pyymal模块使用 Tags:Python Category:Python 博客地址:www.liuyao.me 作者:刘耀 YA ...
随机推荐
- 【ecshop】 完全清除版权信息
完整去掉版权和后门的方法: 去ECSHOP版权,去官方后门,完整版 作者:阿牛 ECShop是一款B2C独立网店系统,适合企业及个人快速构建个性化网上商店.系统开源但不免费,是基于PHP语言及MYSQ ...
- Java虚拟机原理图解
具体详情参考: http://blog.csdn.net/luanlouis/article/details/41046443 http://blog.csdn.net/luanlouis/artic ...
- LeetCode - PlusOne
题意:给一个数按位存放在一个int数组中,要求返回这个数加一后的数组. 懒人解法: public class Solution { public int[] plusOne(int[] digits) ...
- JavaWeb温习之HttpServletResponse对象
以下内容均根据"方立勋JavaWeb视频教程"进行总结 1. HttpServletResponse常见应用——设置响应头控制浏览器的行为 1.1 设置http响应头控制浏览器禁止 ...
- CSS 3D的应用记录
为父元素添加以下样式后,子元素即可使用3D属性,例如translateZ /*设置子元素也应用3D效果*/-webkit-transform-style: preserve-3d;-moz-trans ...
- shell中特殊变量$0 $1 $# $$ $! $?的涵义
$0: 执行脚本的名字 $*和$@: 将所有参数返回 $#: 参数的个数 $_: 代表上一个命令的最后一个参数 $$: 代表所在命令的PID $!: 代表最后执行的后台命令的PID $?: 代表上一个 ...
- C# 关于调用office com组件导出Excel
服务器环境: 环境为win2008 r2,系统为64位,程序是C#的winform.因为需要处理数据,然后生成Excel,耗时太长,就使用了多线程.winform程序是由计划任务启动,每天晚上去跑. ...
- 【BZOJ4195】[Noi2015]程序自动分析 并查集
[BZOJ4195][Noi2015]程序自动分析 Description 在实现程序自动分析的过程中,常常需要判定一些约束条件是否能被同时满足. 考虑一个约束满足问题的简化版本:假设x1,x2,x3 ...
- 微信小程序 --- app.json文件
app.json文件用于配置项目:用于对小程序进行全局设置: pages:定义小程序的路由.(凡是不在这个配置里面的东西,都无法打开) (特别注意:结尾不能有 逗号 否则会出错) window:定义小 ...
- PHP中文字数限制:中文字符串截取(mb_substr)
一.中文截取:mb_substr() mb_substr( $str, $start, $length, $encoding ) $str,需要截断的字符串 $start,截断开始处,起始处为0 $l ...