MOOC用Python玩转数据笔记 2

来源:互联网 发布:sql join left join 编辑:程序博客网 时间:2024/06/04 20:12

pandas

pandas 结合Series和DataFrame的某些绘图功能,还能用pylot函数
方便从csv中读取文件
自己试过的代码:
pandas.read_csv(“*.csv”)
read_excel(“*.xlsx”, “Sheet1”) 读取表格

想试但怕麻烦的代码(主要练习DataFrame):
先将数据形成一种结构:
df = pandas.DataFrame(quotes)
再存入表格:
df.to_excel("***.xls, sheet_name="***")

做题目(增加一列sum数据):
这里写图片描述

这里写图片描述

>>> import pandas as pd>>> exc=pd.read_excel(r"C:\Users\Administrator\Desktop\f.xlsx","Sheet1")>>> sum = []>>> for index, row in exc.iterrows():  ...     newone = row.Python + row.Math...      sum.append(newone) >>> exc["sum"]=sum  #for循环里不写index,sum变量好像就成元组了,就会出错。>>> exc.to_excel(r"C:\Users\Administrator\Desktop\f.xlsx","Sheet2")

最后一行报错

IOError: [Errno 13] Permission denied: 还不会解决。明天再说吧!!!貌似可以用arcpy解决。屁咧。
os.getcwd()
os.chdir()

# mydir = r'C:\Users\Administrator\Desktop'# os.chdir(mydir)# arcpy.env.workspace = "c:/data"  

出现的问题:

1.因为没有某个模块显示运行失败————安装相应模块(link)就行了
2.IOError: [Errno 13] Permission denied: ‘C:\Users\Administrator\Desktop\f.xlsx’ 貌似属于管理员权限问题

一直伴随的问题:

$ echo $PATH #意思是显示路径-------$ echo $HOME #(同$ echo ~)意思是当前用户主目录------->>>os.getcwd()  #获取当前工作目录-------?os.path.join() #干啥用的,咋用?------->>>os.environ

以下杂,作为搜索脉络吧:

http://matplotlib.org/examples/animation/animate_decay.html
聚类分析之一K均值算法

刚认识的新词:
聚类中心 均方差 测度函数 收敛

聚类算法包:
- 机器学习包scikit-learn
- 这里用SciPy.cluster.vq的kmeans()和vq()
堆积数据:vstack()

Matplotlib绘图基础
包含绘图模块
- 绘图API——pyplot模块
- 集成库——pylab(numpy,pylot中常用函数)

查看颜色和样式
import matplotlib.pyplot as plt
help(plt.plot)

文字设置

0 0
原创粉丝点击