我正在尝试使用具有不连续X轴的pyplot创build一个图表。 通常的方式是绘制坐标轴,像这样: (值)—- // —-(后面的值) //表示你正在跳过(值)和(后面的值)之间的所有内容。 我一直没有find任何这样的例子,所以我想知道是否有可能。 我知道你可以通过例如财务数据的不连续性来join数据,但是我想让这个轴的跳跃更加明确。 目前我只是使用子图,但我最终希望所有的东西都在同一个图上。
可能重复: 错误:无法findvcvarsall.bat 我试图为Python安装MySql接口,但我得到一个错误(下面提到)。 我知道解决scheme:安装Microsoft Visual C ++。 除了安装Microsoft Visual C ++之外,是否还有其他解决scheme? 我的意思是这真的伤害了我; 为什么要安装Microsoft Visual C ++只是为了构build这个单一的包,从开发人员的angular度来看,这是一个无用的浪费时间的方法。 这个问题有没有其他解决scheme? MySQL-python-1.2.3c1>setup.py install running install running bdist_egg running egg_info writing MySQL_python.egg-info\PKG-INFO writing top-level names to MySQL_python.egg-info\top_level.txt writing dependency_links to MySQL_python.egg-info\dependency_links.txt reading manifest file 'MySQL_python.egg-info\SOURCES.txt' reading manifest template 'MANIFEST.in' writing manifest file 'MySQL_python.egg-info\SOURCES.txt' installing library code to build\bdist.win32\egg running install_lib […]
在Python中使用matplotlib从pandas数据matplotlib制作一系列散点图的最佳方法是什么? 例如,如果我有一个数据框df有一些感兴趣的列,我发现自己通常转换所有的数组: import matplotlib.pylab as plt # df is a DataFrame: fetch col1 and col2 # and drop na rows if any of the columns are NA mydata = df[["col1", "col2"]].dropna(how="any") # Now plot with matplotlib vals = mydata.values plt.scatter(vals[:, 0], vals[:, 1]) 在绘图之前把所有东西都转换成数组的问题是,它迫使你摆脱数据框。 考虑以下两种使用情况,其中具有完整的数据框对绘图至关重要: 例如,如果您现在想要查看col3所有值,以查找在调用中绘制的相应值以scatter ,并按照该值对每个点(或大小)进行着色? 你必须回去,拉出col1,col2的非na值col1,col2并检查它们相应的值。 有没有一种方法来绘制,同时保留数据框? 例如: mydata = df.dropna(how="any", subset=["col1", "col2"]) […]
我怎样才能从控制台python应用程序轮询键盘? 具体来说,我想在很多其他I / O活动(套接字select,串口访问等)中做类似的事情: while 1: # doing amazing pythonic embedded stuff # … # periodically do a non-blocking check to see if # we are being told to do something else x = keyboard.read(1000, timeout = 0) if len(x): # ok, some key got pressed # do something 什么是在Windows上这样做的正确pythonic方式? 而且,Linux的可移植性不会太差,尽pipe这不是必需的。
在[i][j]被写入时,numpy中是否有一个智能且空间对称的matrix自动(并且透明地)填充[j][i]处的位置? import numpy a = numpy.symmetric((3, 3)) a[0][1] = 1 a[1][0] == a[0][1] # True print(a) # [[0 1 0], [1 0 0], [0 0 0]] assert numpy.all(a == aT) # for any symmetric matrix 一个自动的埃米特文也会很好,虽然在写作的时候我不需要这个。
我有下面的代码,它只是在一个字典中打印键/值对(对按键sorting): for word, count in sorted(count_words(filename).items()): print word, count 但是,调用iteritems()而不是items()会生成相同的输出 for word, count in sorted(count_words(filename).iteritems()): print word, count 现在,在这种情况下我应该select哪一个呢? 我咨询了Python教程,但并没有真正回答我的问题。
此代码打开url并在末尾附加/names ,并打开页面并将string打印到test1.csv : import urllib2 import re import csv url = ("http://www.example.com") bios = [u'/name1', u'/name2', u'/name3'] csvwriter = csv.writer(open("/test1.csv", "a")) for l in bios: OpenThisLink = url + l response = urllib2.urlopen(OpenThisLink) html = response.read() item = re.search('(JD)(.*?)(\d+)', html) if item: JD = item.group() csvwriter.writerow(JD) else: NoJD = "NoJD" csvwriter.writerow(NoJD) 但是我得到这个结果: J,D,",", ,C,o,l,u,m,b,i,a, ,L,a,w, […]
我有一个OHLC价格数据集,我已经从CSVparsing成pandas数据框,并重新采样到15分钟的酒吧: <class 'pandas.core.frame.DataFrame'> DatetimeIndex: 500047 entries, 1998-05-04 04:45:00 to 2012-08-07 00:15:00 Freq: 15T Data columns: Close 363152 non-null values High 363152 non-null values Low 363152 non-null values Open 363152 non-null values dtypes: float64(4) 我想添加各种计算列,从简单的例如Range(HL)开始,然后用布尔值来表示我将要定义的价格模式的出现,例如一个蜡烛模式, def closed_in_top_half_of_range(h,l,c): return c > l + (h-1)/2 def lower_wick(o,l,c): return min(o,c)-l def real_body(o,c): return abs(co) def lower_wick_at_least_twice_real_body(o,l,c): return lower_wick(o,l,c) >= […]
典型的标题应该是 #!/usr/bin/env python 但是我发现下面的代码在执行$python ./my_script.py这样的脚本时也是$python ./my_script.py #!/usr/bin/python #!python 这两个头文件有什么区别? 第二个问题可能是什么? 请同时讨论python解释器在PATH中的情况。 谢谢。
使用标准的Python数组,我可以做到以下几点: arr = [] arr.append([1,2,3]) arr.append([4,5,6]) # arr is now [[1,2,3],[4,5,6]] 但是,我不能在numpy中做同样的事情。 例如: arr = np.array([]) arr = np.append(arr, np.array([1,2,3])) arr = np.append(arr, np.array([4,5,6])) # arr is now [1,2,3,4,5,6] 我也研究过vstack ,但是当我在一个空数组上使用vstack时,我得到: ValueError: all the input array dimensions except for the concatenation axis must match exactly 那么我怎么做一个新的行添加到numpy中的空数组?