代码

import pandas as pd
import numpy as np dates = pd.date_range('20130101', periods=6)
df=pd.DataFrame(np.arange(24).reshape((6,4)),index=dates, columns=['A','B','C','D']) # 行数,列数,赋值
df.iloc[1,2] = 1111
df.loc['20130101','B'] = 2222
print('-1-')
print(df) df[df.A>4] = 0
print('-2-')
print(df) df.A[df.A>4] = 0
print('-3-')
print(df) # 添加列
df['F'] = np.nan
print('-4-')
print(df) df['E'] = pd.Series([1,2,3,4,5,6],index=pd.date_range('20130101',periods=6))
print('-5-')
print(df)

  

输出

-1-
A B C D
2013-01-01 0 2222 2 3
2013-01-02 4 5 1111 7
2013-01-03 8 9 10 11
2013-01-04 12 13 14 15
2013-01-05 16 17 18 19
2013-01-06 20 21 22 23
-2-
A B C D
2013-01-01 0 2222 2 3
2013-01-02 4 5 1111 7
2013-01-03 0 0 0 0
2013-01-04 0 0 0 0
2013-01-05 0 0 0 0
2013-01-06 0 0 0 0
-3-
A B C D
2013-01-01 0 2222 2 3
2013-01-02 4 5 1111 7
2013-01-03 0 0 0 0
2013-01-04 0 0 0 0
2013-01-05 0 0 0 0
2013-01-06 0 0 0 0
-4-
A B C D F
2013-01-01 0 2222 2 3 NaN
2013-01-02 4 5 1111 7 NaN
2013-01-03 0 0 0 0 NaN
2013-01-04 0 0 0 0 NaN
2013-01-05 0 0 0 0 NaN
2013-01-06 0 0 0 0 NaN
-5-
A B C D F E
2013-01-01 0 2222 2 3 NaN 1
2013-01-02 4 5 1111 7 NaN 2
2013-01-03 0 0 0 0 NaN 3
2013-01-04 0 0 0 0 NaN 4
2013-01-05 0 0 0 0 NaN 5
2013-01-06 0 0 0 0 NaN 6

  

最新文章

  1. 【爬虫】python之BeautifulSoup用法
  2. Android文件系统的结构
  3. 获取枚举类型的描述description
  4. HTML 的 <div> 和 <span> 标签
  5. html文本框(input)不保存缓存记录
  6. 浏览器中 for in 反射 对象成员 的差异
  7. IntelliJ IDEA对开发者的三大诱惑
  8. Fiddler抓取https设置及其原理
  9. 利用JS去做响应式布局
  10. Guava 教程1-使用 Google Collections,Guava,static imports 编写漂亮代码
  11. 【原创】大叔经验分享(18)hive2.0以后通过beeline执行sql没有进度信息
  12. ICSE 2018 论文
  13. python专题 --- 递归
  14. 动手动脑(lesson 8)
  15. elasticsearch 基本操作
  16. 7.final关键字.md
  17. Orchard模块开发全接触8:改造后台
  18. MySQL Crash Course #01# Chapter 1. 2 概念. Primary key
  19. SaltStack一键部署负载均衡和高可用
  20. KClient——kafka消息中间件源码解读

热门文章

  1. css3/sass 样式记录
  2. ionic4打包和ngix配置
  3. 2019 SDN阅读作业
  4. nanopor软件列表
  5. win10 去除快捷方式小箭头
  6. Unity 2018 Cookbook (Matt Smith 著)
  7. vue使用--saas的引入与使用
  8. eclipse 离线安装SVN插件(支持eclipse201909)
  9. LeetCode 200:岛屿数量 Number of Islands
  10. javascript 写一个 map方法