spyder

独家 | 10个数据科学家常犯的编程错误(附解决方案)

僤鯓⒐⒋嵵緔 提交于 2019-11-29 00:22:07
数据科学家是“比软件工程师更擅长统计学,比统计学家更擅长软件工程的人”。许多数据科学家都具有统计学背景,但是在软件工程方面的经验甚少。我是一名资深数据科学家,在Stackoverflow的python编程方面排名前1%,并与许多(初级)数据科学家共事。以下是我经常看到的10大常见错误,本文将为你相关解决方案: 不共享代码中引用的数据 对无法访问的路径进行硬编码 将代码与数据混合 在Git中和源码一起提交数据 编写函数而不是DAG 写for循环 不编写单元测试 不写代码说明文档 将数据保存为csv或pickle文件 使用jupyter notebook 1. 不共享代码中引用的数据 数据科学需要代码和数据。因此,为了让别人可以复现你的结果,他们需要能够访问到数据。道理很简单,但是很多人忘记分享他们代码中的数据。 import pandas as pd df1 = pd.read_csv('file-i-dont-have.csv') # fails do_stuff(df) 解决方案:使用d6tpipe( https://github.com/d6t/ d6tpipe)来共享你的代码中的数据文件、将其上传到S3/web/google驱动等,或者保存到数据库,以便于别人可以检索到文件(但是不要将其添加到git,原因见下文)。 2. 对无法访问的路径进行硬编码 与错误1相似

Python Spyder reset

爷,独闯天下 提交于 2019-11-28 21:24:08
I was using python(x,y), which came with Spyder. Yesterday, Spyder crashed I can't figure it out how to fix it. I uninstalled python(x,y) and reinstalled, still the same problem. If I try to open Spyder I get this message: Spyder crashed during last session If Spyder does not start at all and before submitting a bug report, please try to reset setting to defaults by running Spyder with the command line option '--reset: python spyder --reset Of course, I tried to do the above, but it doesn't seem like I have Spyder in my path. When I try to put python spyder --reset in my command prompt window,

When running PyQt5 app in Spyder it always exits with -1

孤街浪徒 提交于 2019-11-28 11:44:58
I am learning to program with PyQt5. No troubles with that, but there is one annoying issue: when I start the app, I immediately get the message that an exception occurred and SystemExit: -1 is repported (see below). An exception has occurred, use %tb to see the full traceback. SystemExit: -1 /home/arnold/bin/anaconda3/envs/ml-gpu/lib/python3.5/site-packages/IPython/core/interactiveshell.py:2918: UserWarning: To exit: use 'exit', 'quit', or Ctrl-D. warn("To exit: use 'exit', 'quit', or Ctrl-D.", stacklevel=1) In [2]: %tb Traceback (most recent call last): File "<ipython-input-1-f5ccc42a06e6>",

Logging input and output in Spyder's console

ε祈祈猫儿з 提交于 2019-11-28 10:23:32
问题 I learnt data manipulation and analysis through Stata and I used the log command to record all the commands written and the output generated. Doing so I could reproduce my findings, check previous results and share it with others in pdf or txt. What to use with Python? Is there a difference if I use a Python Jupyter Notebook or Spyder? 回答1: The way to do what you want is by using the %logstart command, as described here: Log IPython output? 回答2: Stop using the python interpreter and start

visualize plotly charts in spyder

南楼画角 提交于 2019-11-28 08:20:45
问题 Since November 2015, plotly is Open-Source and available for python. https://plot.ly/javascript/open-source-announcement/ When trying to do some plots offline, these work in iPython Notebook (version 4.0.4) But if I try to run them in Spyder (version 2.3.8), i just get the following output: <IPython.core.display.HTML object> <IPython.core.display.HTML object> There's something wrong in my code or the iPython Terminal of Spyder still doesn't support this? Here goes the example code (taken from

'Syntax Error: invalid syntax' for no apparent reason

守給你的承諾、 提交于 2019-11-28 05:23:36
I've been trying to get a fix and can't find why the error keeps appearing. Pmin,Pmax,w,fi1 and fi2 have all been assigned finite values guess=Pmin+(Pmax-Pmin)*((1-w**2)*fi1+(w**2)*fi2) When i remove this line from the code, the same error appears at the next line of code, again for no reason I can think of Edit: Here is the chunk of code I was referring to: def Psat(self, T): pop= self.getPborder(T) boolean=int(pop[0]) P1=pop[1] P2=pop[2] if boolean: Pmin = float(min([P1, P2])) Pmax = float(max([P1, P2])) Tr=T/self.typeMolecule.Tc w=0.5*(1+scipy.tanh((10**5)*(Tr-0.6))) fi1=0.5*(1-scipy.tanh(8

'import sitecustomize' failed upon starting spyder

自作多情 提交于 2019-11-28 01:12:07
问题 I am trying to install python. Or actually, have installed and deinstalled it a few times now. I am using pythonxy with the spyder IDE (i am used to matlab is why i want to use spyder). The 3.3.2 python would not even start with spyder on my win8 machine, so now I have the 2.7 version installed. Spyder starts up now, but upon startup I get `'import sitecustomize' failed? in my console and python wont execute any commands I enter. After the error the startupscript keeps on going forever

Python kernel dies for second run of PyQt5 GUI

末鹿安然 提交于 2019-11-28 00:12:53
问题 Using Spyder in Python 3.5.2 |Anaconda 4.2.0 (64-bit) Windows package. qt: 5.6.0 For first run, GUI window opens as expected For 2nd run, nothing opens, and receiving Kernel died, restarting log message. gui1.py: import sys from PyQt5.QtWidgets import QApplication, QWidget app = QApplication(sys.argv) w = QWidget() w.resize(250,150) w.show() #sys.exit(app.exec_()) app.exec_() IPhython log: runfile('F:/work/ws_python/TestProj1/gui1/gui1.py', wdir='F:/work/ws_python/TestProj1/gui1') runfile('F:

how to execute Python 3.3 script in Spyder console with variables?

怎甘沉沦 提交于 2019-11-27 23:31:56
问题 how can I execute Python 3.3 script in Spyder console, and that has variables? My sample code (C:/test/myfile.py) is from sys import argv script, first, second, third = argv print("The script is called:", script) print("Your first variable is:", first) print("Your second variable is:", second) print("Your third variable is:", third) I have tried exec(open("C:\test\myfile.py").read()) - and the error I get is "ValueError: need more than 1 value to unpack. I want to supply the variables first =

downloading error using nltk.download()

↘锁芯ラ 提交于 2019-11-27 20:40:41
I am experimenting NLTK package using Python. I tried to downloaded NLTK using nltk.download() . I got this kind of error message. How to solve this problem? Thanks. The system I used is Ubuntu installed under VMware. The IDE is Spyder. After using nltk.download('all') , it can download some packages, but it gets error message when downloading oanc_masc To download a particular dataset/models, use the nltk.download() function, e.g. if you are looking to download the punkt sentence tokenizer, use: $ python3 >>> import nltk >>> nltk.download('punkt') If you're unsure of which data/model you need