代码

import pandas as pd
import numpy as nps = pd.Series([1,3,6,np.nan, 44,1])print('-1-')
print(s)dates = pd.date_range('20160101', periods=6)
print('-2-')
print(dates)# index 是行的key; 默认就是数字
df = pd.DataFrame(np.random.randn(6,4), index=dates, columns=['a','b','c','d'])
print('-3-')
print(df)df1 = pd.DataFrame(np.arange(12).reshape((3,4)))
print('-4-')
print(df1)df2 = pd.DataFrame({'A':1.,
'B':pd.Timestamp('20130102'),
'C':pd.Series(1,index=list(range(4)), dtype = 'float32'),
'D':np.array([3]*4,dtype='int32'),
'E':pd.Categorical(["test","train","test","train"]),
'F':'foo'})
print('-5-')
print(df2)
print('-6-')
print(df2.dtypes)
print('-7-')
print(df2.index)
print('-8-')
print(df2.columns)
print('-9-')
print(df2.values)print('-10-')
#只会计算数字串
print(df2.describe())print('-11-')
print(df2.T)print('-12-')
# 对 ABCD排序
print(df2.sort_index(axis=1, ascending=False))print('-13-')
# 对123排序
print(df2.sort_index(axis=0, ascending=False))print('-14-')
print(df2.sort_values(by='E'))

  

输出

-1-
0     1.0
1     3.0
2     6.0
3     NaN
4    44.0
5     1.0
dtype: float64
-2-
DatetimeIndex(['2016-01-01', '2016-01-02', '2016-01-03', '2016-01-04','2016-01-05', '2016-01-06'],dtype='datetime64[ns]', freq='D')
-3-a         b         c         d
2016-01-01 -0.636080 -0.411646  1.167693 -0.085643
2016-01-02 -0.931738 -0.656105  0.833493  0.866367
2016-01-03 -0.495047 -0.131291 -0.757423 -0.783154
2016-01-04 -0.207423  0.261732  0.300315 -0.674217
2016-01-05  0.241664  0.560630 -0.057852 -0.411710
2016-01-06 -0.964392  0.990477  0.926594  0.388210
-4-0  1   2   3
0  0  1   2   3
1  4  5   6   7
2  8  9  10  11
-5-A          B    C  D      E    F
0  1.0 2013-01-02  1.0  3   test  foo
1  1.0 2013-01-02  1.0  3  train  foo
2  1.0 2013-01-02  1.0  3   test  foo
3  1.0 2013-01-02  1.0  3  train  foo
-6-
A           float64
B    datetime64[ns]
C           float32
D             int32
E          category
F            object
dtype: object
-7-
Int64Index([0, 1, 2, 3], dtype='int64')
-8-
Index(['A', 'B', 'C', 'D', 'E', 'F'], dtype='object')
-9-
[[1.0 Timestamp('2013-01-02 00:00:00') 1.0 3 'test' 'foo'][1.0 Timestamp('2013-01-02 00:00:00') 1.0 3 'train' 'foo'][1.0 Timestamp('2013-01-02 00:00:00') 1.0 3 'test' 'foo'][1.0 Timestamp('2013-01-02 00:00:00') 1.0 3 'train' 'foo']]
-10-A    C    D
count  4.0  4.0  4.0
mean   1.0  1.0  3.0
std    0.0  0.0  0.0
min    1.0  1.0  3.0
25%    1.0  1.0  3.0
50%    1.0  1.0  3.0
75%    1.0  1.0  3.0
max    1.0  1.0  3.0
-11-0         ...                             3
A                    1         ...                             1
B  2013-01-02 00:00:00         ...           2013-01-02 00:00:00
C                    1         ...                             1
D                    3         ...                             3
E                 test         ...                         train
F                  foo         ...                           foo[6 rows x 4 columns]
-12-F      E  D    C          B    A
0  foo   test  3  1.0 2013-01-02  1.0
1  foo  train  3  1.0 2013-01-02  1.0
2  foo   test  3  1.0 2013-01-02  1.0
3  foo  train  3  1.0 2013-01-02  1.0
-13-A          B    C  D      E    F
3  1.0 2013-01-02  1.0  3  train  foo
2  1.0 2013-01-02  1.0  3   test  foo
1  1.0 2013-01-02  1.0  3  train  foo
0  1.0 2013-01-02  1.0  3   test  foo
-14-A          B    C  D      E    F
0  1.0 2013-01-02  1.0  3   test  foo
2  1.0 2013-01-02  1.0  3   test  foo
1  1.0 2013-01-02  1.0  3  train  foo
3  1.0 2013-01-02  1.0  3  train  foo

  

转载于:https://www.cnblogs.com/alexYuin/p/9601904.html

13-numpy笔记-莫烦pandas-1相关推荐

  1. 【笔记|莫烦老师《数据处理》】:numpy、pandas、matplotlib【完结】

    2021.1.20 第一部分:[python3] [python3]1.break和 continue: https://blog.csdn.net/wistonty11/article/detail ...

  2. numpy学习笔记(莫烦python)

    import numpy as np numpy属性 array = np.array([[1,2,3],[2,3,4]]) print(array) print('number of dim',ar ...

  3. 莫烦Python NumpyPandas 学习笔记

    莫烦Python Numpy&Pandas 学习笔记 原文(视频)地址:https://www.bilibili.com/video/BV1Ex411L7oT 1. 安装 numpy官方网站: ...

  4. tensorflow学习笔记-bili莫烦

    bilibili莫烦tensorflow视频教程学习笔记 1.初次使用Tensorflow实现一元线性回归 # 屏蔽警告 import os os.environ['TF_CPP_MIN_LOG_LE ...

  5. scikit-learn学习笔记-bili莫烦

    bilibili莫烦scikit-learn视频学习笔记 1.使用KNN对iris数据分类 from sklearn import datasets from sklearn.model_select ...

  6. 【莫烦Python】Numpy教程

    目录 前言 1.numpy属性 2.numpy的array创建 3.numpy的基础运算 4.numpy的基础运算2 5.numpy的索引 6.numpy的array合并 7.numpy的array分 ...

  7. 【莫烦Python】Pandas教程

    目录 前言 1.Pandas vs Numpy 2.基本介绍 3.选择数据 4.设置值 5.处理丢失的数据 6.pandas导入导出 7.pandas合并concat 8.pandas合并merge ...

  8. python中matplotlib画图_Python-matplotlib画图(莫烦笔记)

    这个是我对于莫烦老师的matplotlib模块的视频做的一个笔记. 1.前言 Matplotlib是一个python的 2D绘图库,它以各种硬拷贝格式和跨平台的交互式环境生成出版质量级别的图形.通过M ...

  9. 莫烦强化学习笔记整理(九)DDPG

    莫烦强化学习笔记整理(九)DDPG 1.DDPG 要点 2.DDPG 算法 actor critic actor与critic结合 类似于DQN的记忆库 回合更新 链接: DDPG代码. 1.DDPG ...

最新文章

  1. 2021-2027年中国一氧化氮行业市场研究及前瞻分析报告
  2. python储存在ftp_python实现FTP
  3. paloalto防火墙版本升级
  4. php 预处理原理,PHP的PDO对象预处理的2种实现方法,实现原理详解
  5. thinkphp5.0.9预处理导致的sql注入复现与详细分析
  6. java8 hashmap 死循环_踩坑了,JDK8中HashMap依然会死循环!
  7. c++ 重载 覆盖 隐藏的区别和执行方式
  8. 旷视提出Circle Loss,革新深度特征学习范式 |CVPR 2020 Oral
  9. Flutter中为图片设置波纹点击效果
  10. xampp mysql是空的_xampp中修改mysql默认空密码(root密码)的方法分享
  11. 疑似一加7渲染图曝光:弹出式自拍镜头+高颜值渐变配色
  12. Java阶段2-02JS:08ECMAScript BOM DOM:
  13. 大熊君学习html5系列之------Online Offline(在线状态检测)
  14. 解决oracle11g连接失败 ORA-01034: ORACLE not available ORA-27101: shared memory realm does not exist
  15. oracle merge into 优化,ORACLE 10g 的 merge into用法
  16. 手把手教你自学单片机,三个步骤请做好笔记
  17. 【大一期末项目】qqclienkey利用:基于qqclientkey的纯c++项目实践
  18. 「津津乐道播客」#353 编码人声:程序员都是「时间管理大师」
  19. openwrt路由器打印机服务器设置_OpenWRT路由器——网络打印服务器
  20. Linux学习(六):proftpd搭建,完美解决vsftpd中文引号bug

热门文章

  1. 《C++编程惯用法——高级程序员常用方法和技巧》——2.9 静态对象的构造
  2. shiro的简单使用
  3. Servlet页面间对象传递的方法
  4. 配置kickstart脚本--图形篇
  5. 修改ActiveProcessLinks链表隐藏进程
  6. 算法时间复杂度和空间复杂度表示
  7. C# 设置Menustrip提示框的显示
  8. /lib64/libc.so.6 is not a symbolic link 解决方法
  9. php定义枚举,PHP中Enum(枚举)用法实例详解
  10. JS中 let 和var的区别