最近在学习Python,当学习到Pandas这个包的时候,第一要务肯定就是要安装这个包啦,然后在iTerm中输入安装命令pip install pandas,结果报错啦:
OSError: [Errno 1] Operation not permitted
Exception:
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/pip/basecommand.py", line 215, in main
status = self.run(options, args)
File "/Library/Python/2.7/site-packages/pip/commands/install.py", line 342, in run
prefix=options.prefix_path,
File "/Library/Python/2.7/site-packages/pip/req/req_set.py", line 778, in install
requirement.uninstall(auto_confirm=True)
File "/Library/Python/2.7/site-packages/pip/req/req_install.py", line 754, in uninstall
paths_to_remove.remove(auto_confirm)
File "/Library/Python/2.7/site-packages/pip/req/req_uninstall.py", line 115, in remove
renames(path, new_path)
File "/Library/Python/2.7/site-packages/pip/utils/__init__.py", line 267, in renames
shutil.move(old, new)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 302, in move
copy2(src, real_dst)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 131, in copy2
copystat(src, dst)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 103, in copystat
os.chflags(dst, st.st_flags)
OSError: [Errno 1] Operation not permitted: '/var/folders/j1/8mwmv4vn2vl45dy5y8ffm45w0000gn/T/pip-sX2pPv-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy-1.8.0rc1-py2.7.egg-info'
搜索了几下,问题解决,pandas包也安装好了。
首先输入
pip install numpy --upgrade --ignore-installed
然后
pip install pandas
接着愉快地学习pandas...
pandas读取中文乱码
import pandas as pd
posidata = pd.read_csv("/xxx/position.csv")
一开始尝试了utf8,结果是不行的,后来又尝试了如下三种编码,搞定!
posidata = pd.read_csv("/xxx/position.csv",encoding="gb18030")
posidata = pd.read_csv("/xxx/position.csv",encoding="gb2312")
posidata = pd.read_csv("/xxx/position.csv",encoding="gbk")