Python----Pandas
来源:互联网 发布:服装吊牌制作软件 编辑:程序博客网 时间:2024/05/29 10:58
Python—-Pandas
JSON:JavaScript 对象表示法(JavaScript Object Notation)。
JSON 是存储和交换文本信息的语法。类似 XML。
JSON 比 XML 更小、更快,更易解析。
1.json的语法规则
import numpy as npimport pandas as pd dates=pd.date_range('20171119',periods=6)df=pd.DataFrame(np.arange(24).reshape((6,4)),index=dates,columns=['A','B','C','D'])print(df)
输出
A B C D
2017-11-19 0 1 2 3
2017-11-20 4 5 6 7
2017-11-21 8 9 10 11
2017-11-22 12 13 14 15
2017-11-23 16 17 18 19
2017-11-24 20 21 22 23
print(df['A'])
2017-11-19 0
2017-11-20 4
2017-11-21 8
2017-11-22 12
2017-11-23 16
2017-11-24 20
print(df.A)#作用同上```
print(df.loc[‘20171121’])
A 8
B 9
C 10
D 11
Name: 2017-11-21 00:00:00, dtype: int32
print(df.loc[‘20171119’,[‘A’]])
A 0
Name: 2017-11-19 00:00:00, dtype: int32
print(df.iloc[3])
A 12
B 13
C 14
D 15
Name: 2017-11-22 00:00:00, dtype: int32
print(df.iloc[1:3])
A B C D
2017-11-20 4 5 6 7
2017-11-21 8 9 10 11
print(df.iloc[1:3,1:3])
B C
2017-11-20 5 6
2017-11-21 9 10
print(df.iloc[[1,5,3],1:3])
B C
2017-11-20 5 6
2017-11-24 21 22
2017-11-22 13 14
print(df.ix[:2,[‘A’,’C’]])
A C
2017-11-19 0 2
2017-11-20 4 6
print(df[df.A>8])
A B C D
2017-11-22 12 13 14 15
2017-11-23 16 17 18 19
2017-11-24 20 21 22 23
print(df.A>8)
2017-11-19 False
2017-11-20 False
2017-11-21 False
2017-11-22 True
2017-11-23 True
2017-11-24 True
Freq: D, Name: A, dtype: bool
df.iloc[2,2]=50
print(df)
A B C D
2017-11-19 0 1 2 3
2017-11-20 4 5 6 7
2017-11-21 8 9 50 11
2017-11-22 12 13 14 15
2017-11-23 16 17 18 19
2017-11-24 20 21 22 23
df.loc[‘20171119’,’B’]=56
print(df)
A B C D
2017-11-19 0 56 2 3
2017-11-20 4 5 6 7
2017-11-21 8 9 50 11
2017-11-22 12 13 14 15
2017-11-23 16 17 18 19
2017-11-24 20 21 22 23
df[df.A>4]=0
print(df)
A B C D
2017-11-19 0 56 2 3
2017-11-20 4 5 6 7
2017-11-21 0 0 0 0
2017-11-22 0 0 0 0
2017-11-23 0 0 0 0
2017-11-24 0 0 0 0
df=pandas.DataFrame(np.arange(24).reshape((6,4)),index=dates,columns=[‘A’,’B’,’C’,’D’])
print(df)
A B C D
2017-11-19 0 1 2 3
2017-11-20 4 5 6 7
2017-11-21 8 9 10 11
2017-11-22 12 13 14 15
2017-11-23 16 17 18 19
2017-11-24 20 21 22 23
df.A[df.A>4]=0
print(df)
A B C D
2017-11-19 0 1 2 3
2017-11-20 4 5 6 7
2017-11-21 0 9 10 11
2017-11-22 0 13 14 15
2017-11-23 0 17 18 19
2017-11-24 0 21 22 23
df[‘E’]=pandas.Series([1,2,3,4,5,6],index=pandas.date_range(‘20171119’,periods=6))
print(df)
A B C D E
2017-11-19 0 1 2 3 1
2017-11-20 4 5 6 7 2
2017-11-21 0 9 10 11 3
2017-11-22 0 13 14 15 4
2017-11-23 0 17 18 19 5
2017-11-24 0 21 22 23 6
“`
- python pandas
- python-pandas
- python pandas
- Python -- pandas
- Python - Pandas
- python-pandas
- Python pandas
- python pandas
- Python----Pandas
- python-pandas
- Python中的pandas模块
- Python Pandas基础1
- Python pandas基础2
- python pandas基础3
- Python安装pandas,matplotlib
- python之pandas说明
- python中的pandas包
- python中安装pandas
- JAVA案例练习 -特定日期格式
- 使用redis生成全局唯一id
- bzoj1487 无归岛
- ES6-变量的结构赋值-数组
- osmdroid API解读(六)
- Python----Pandas
- TTL电平、COMS电平、232电平、USB电平的区别与转换方法
- 第四周 项目3
- 调用webservise常用方法
- 工厂模式
- Spring事务传播问题小案例
- [NOIP2017模拟]乘积
- 数据库查询结果封装List<Map<String,String>>
- Java关于浮点数的舍入法与String.format()在不同jdk版本的区别