在查看了读取url链接的不同方法后,指向.xls文件,我决定使用xlrd.
我很难将'xlrd.book.Book'类型转换为'pandas.DataFrame'
我有以下内容:
import pandas
import xlrd
import urllib2
link ='http://www.econ.yale.edu/~shiller/data/chapt26.xls'
socket = urllib2.urlopen(link)
#this line gets me the excel workbook
xlfile = xlrd.open_workbook(file_contents = socket.read())
#storing the sheets
sheets = xlfile.sheets()
Run Code Online (Sandbox Code Playgroud)
我想把最后一张sheets和导入作为一个pandas.DataFrame关于如何实现这一点的任何想法?我试过了,pandas.ExcelFile.parse()但它想要一个excel文件的路径.我当然可以将文件保存到内存然后解析(使用tempfile或者其他),但我正在尝试遵循pythonic指南并使用可能已经写入pandas的功能.
一如既往地非常感谢任何指导.
Markdown 语法不会在Atom.io 中呈现。
以下是其他 sytax 突出显示的屏幕截图,它们完美地工作(而 Markdown 则没有)。
但是,Markdown 语法似乎根本不起作用?
我目前使用的是最稳定的 Atom.io 版本:
benjamingross@myhost:~$ atom --version
Atom : 1.12.7
Electron: 1.3.13
Chrome : 52.0.2743.82
Node : 6.5.0
Run Code Online (Sandbox Code Playgroud)
language-markdown和language-gfm包我都试过了。我什至卸载了这个language-gfm包。.md 文件或.markdown文件不行)我查看了如下所示的其他网页,似乎其他人使用 Atom 突出显示了非常有吸引力的 Markdown 语法。
来自markdown-preview网页
关于如何获得与上述相同的漂亮降价语法高亮的任何想法?
顺便说一句,我的降价预览效果很好......
这是我的结果 ~/.atom/config.cson
benjamingross@myhost:~$ cat ~/.atom/config.cson
"*":
"bracket-matcher":
autocompleteBrackets: false
autocompleteSmartQuotes: false
core:
openEmptyEditorOnStart: false
telemetryConsent: "limited" …Run Code Online (Sandbox Code Playgroud) 我目前有一个numpy多维数组(float类型)和numpy列数组(int类型).我想将两者合并成一个多维的numpy数组.
import numpy
>> dates.shape
(1251,)
>> data.shape
(1251,10)
>> test = numpy.hstack((dates, data))
ValueError: all the input arrays must have same number of dimensions
Run Code Online (Sandbox Code Playgroud)
要显示数组的类型不同:
>> type(dates[0])
<type 'numpy.int64'>
>> type(data[0,0])
<type 'numpy.float64'>
Run Code Online (Sandbox Code Playgroud) 我使用matplotlibscatterplot函数在垂直线上创建句柄的外观以描绘图形的某些部分.但是,为了使它们看起来正确,我需要能够将散点图标记对齐到左边(对于左边的线/描绘边)和/或右(对于右边的线/描边器).
这是一个例子:
#create the figure
fig = plt.figure(facecolor = '#f3f3f3', figsize = (11.5, 6))
ax = plt. ax = plt.subplot2grid((1, 1), (0,0))
#make some random data
index = pandas.DatetimeIndex(start = '01/01/2000', freq = 'b', periods = 100)
rand_levels = pandas.DataFrame( numpy.random.randn(100, 4)/252., index = index, columns = ['a', 'b', 'c', 'd'])
rand_levels = 100*numpy.exp(rand_levels.cumsum(axis = 0))
ax.stackplot(rand_levels.index, rand_levels.transpose())
#create the place holder for the vertical lines
d1, d2 = index[25], index[50]
#draw the lines
ymin, ymax = ax.get_ylim() …Run Code Online (Sandbox Code Playgroud) 如果我使用以下方法构建一个pandas.DataFrame,我得到一个输出(我认为)是特殊的:
import pandas, numpy
df = pandas.DataFrame(
numpy.random.rand(100,2), index = numpy.arange(100), columns = ['s1','s2'])
smoothed = pandas.DataFrame(
pandas.ewma(df, span = 21), index = df.index, columns = ['smooth1','smooth2'])
Run Code Online (Sandbox Code Playgroud)
当我去看平滑的值时,我得到:
>>> smoothed.tail()
smooth1 smooth2
95 NaN NaN
96 NaN NaN
97 NaN NaN
98 NaN NaN
99 NaN NaN
Run Code Online (Sandbox Code Playgroud)
这似乎是以下碎片调用的聚合,产生不同的结果:
smoothed2 = pandas.DataFrame(pandas.ewma(df, span = 21))
smoothed2.index = df.index
smoothed2.columns = ['smooth1','smooth2']
Run Code Online (Sandbox Code Playgroud)
再次使用DataFrame.tail()我得到的调用:
>>> smoothed2.tail()
smooth1 smooth2
95 0.496021 0.501153
96 0.506118 0.507541
97 0.516655 0.544621
98 0.520212 …Run Code Online (Sandbox Code Playgroud) python ×4
numpy ×2
pandas ×2
atom-editor ×1
markdown ×1
matplotlib ×1
scatter-plot ×1
url ×1
xlrd ×1