pandas简易学习教程/练习(1)
2017-12-07 16:32
656 查看
pandas是Python处理数据的一个数据分析处理库,这里的代码我都是在anaconda的Jupyter Notebook上运行的,这是个交互式平台可以立马看到结果(很方便),当然也可以在pycharm上运行,如果没有安装运行的环境的可以参考以下博文
http://blog.csdn.net/a_hui_tai_lang/article/details/78689559
废话少说,一切尽在代码之中
代码已经上传到我的GitHub,https://github.com/LoyalWilliams/machinelearning
![](https://img-blog.csdn.net/20171207161349628)
![](https://img-blog.csdn.net/20171207161609640)
![](https://img-blog.csdn.net/20171207161636066)
![](https://img-blog.csdn.net/20171207161803504)
![](https://img-blog.csdn.net/20171207161923201)
![](https://img-blog.csdn.net/20171207162032264)
![](https://img-blog.csdn.net/20171207162153434)
![](https://img-blog.csdn.net/20171207162622214)
![](https://img-blog.csdn.net/20171207162729549)
![](https://img-blog.csdn.net/20171207162832077)
![](https://img-blog.csdn.net/20171207162934201)
http://blog.csdn.net/a_hui_tai_lang/article/details/78689559
废话少说,一切尽在代码之中
代码已经上传到我的GitHub,https://github.com/LoyalWilliams/machinelearning
# coding: utf-8 # In[1]: import pandas #利用pandas读取csv格式的数据 titanic_train=pandas.read_csv("titanic_train.csv") print(type(titanic_train)) print(titanic_train.dtypes) # In[2]: # 显示帮助文档 print(help(pandas.read_csv))
# In[4]: #显示前几条数据,默认显示5条 titanic_train.head()
# In[5]: #显示倒数前几条数据,默认显示5条 titanic_train.tail()
# In[6]: #查看列名字 titanic_train.columns
# In[7]: #查看形状,即维度 titanic_train.shape
# In[9]: #pandas 使用索引定位数据,使用loc函数即可 #Series object representing the row at index 0. print(titanic_train.loc[2])
# In[17]: #通过切片取数据,如取3到6行的数据 titanic_train.loc[3:6]
# In[27]: #取2,5,10的数据,注意这里传入的参数是一个列表 # titanic_train.loc[[2,5,10]]#这条语句与以下两条语句等价 two_five_ten=[2,5,10] titanic_train.loc[two_five_ten]
# In[28]: #通过列名取数据,注意这里传入的参数是一个列表 # titanic_train[["Name","Sex"]]这条语句与以下两条语句等价 name_sex=["Name","Sex"] titanic_train[name_sex]
# In[35]: # 查找列名以e结尾的数据 col_name=titanic_train.columns.tolist() print(col_name) end_with_e_col=[] for c in col_name: if c.endswith("e"): end_with_e_col.append(c) print(end_with_e_col) end_with_data=titanic_train[end_with_e_col] print(end_with_data.head(3))
# In[36]: #增加列操作,注意增加的列的维度必须和原来的dataframe的维度匹配,如下增加一列name2 titanic_train["Name2"]=titanic_train["Name"] titanic_train.head()
# In[48]: #对dataframe进行排序,按年龄来排序 titanic_train.sort_values("Age",inplace=True,ascending=True) titanic_train.head()
相关文章推荐
- pandas简易学习教程/练习(2)
- Spring.NET学习笔记3——实现一个简易的IoC框架(练习篇)(转)
- python 简易学习教程 1
- Ferris教程学习笔记:js示例3.8 简易网页时钟
- 韩顺平_php从入门到精通_视频教程_第4讲_图像_表格_实际应用-菜谱_课堂练习-课程表_学习笔记_源代码图解_PPT文档整理
- Stage3d 由浅到深理解AGAL的管线vertex shader和fragment shader || 简易教程 学习心得 AGAL 非常非常好的入门文章
- Ferris教程学习笔记:js示例2.13 简易JS年历
- Ferris教程学习笔记:js示例2.12 简易选项卡
- CocosCreator游戏开发---菜鸟学习之路(二)SocketIO简易教程
- 机器学习教程之pandas(二)
- UFLDL教程笔记及练习答案三(Softmax回归与自我学习***)
- UFLDL教程笔记及练习答案四(建立分类用深度学习---栈式自编码神经网络)
- 一小时教程 MySQL从安装到使用 详细步骤 完整图文示例练习教程 学习笔记
- Deep Learning 1_深度学习UFLDL教程:Sparse Autoencoder练习(斯坦福大学深度学习教程)
- UFLDL教程笔记及练习答案三(Softmax回归与自我学习***)
- python学习简易教程
- python基础教程_学习笔记8:序列_练习与总结_1
- Shell简易学习练习
- 【教程】简易CDQ分治教程&学习笔记
- python学习教程之Numpy和Pandas的使用