我已经构建了一个图表,我想将其嵌入到HTML文件中.如果我plotly在线使用,它可以按预期工作.但是,如果我使用OFFLINE离线图表工作(即它打开一个单独的HTML图表),但它没有嵌入HTML(nick.html),iframe即为空.
这是我的代码:
fig = dict(data=data, layout=layout)
plotly.tools.set_credentials_file(username='*****', api_key='*****')
aPlot = plotly.offline.plot(fig, config={"displayModeBar": False}, show_link=False,
filename='pandas-continuous-error-bars.html')
html_string = '''
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css">
<style>body{ margin:0 100; background:whitesmoke; }</style>
</head>
<body>
<h1>Monthly Report</h1>
<!-- *** Section 1 *** --->
<h2></h2>
<iframe width="1000" height="550" frameborder="0" seamless="seamless" scrolling="no" \
src="''' + aPlot + '''.embed?width=800&height=550"></iframe>
<p> (Insights).</p>
</body>
</html>'''
f = open("C:/Users/nicholas\Desktop/nick.html",'w')
f.write(html_string)
f.close()
Run Code Online (Sandbox Code Playgroud)
任何人都知道它为什么不嵌入以及如何修复它?
花了很长时间试图找到这个,但卡住了.
我有一个日期列(称为"时间"),其中包含天/小时/分钟等(timedelta).我在我的数据框中创建了一个新列,我希望将'Time'列转换为秒,并将其放在每一行的新列中.
有没有人有任何指针?我在互联网上找到的就是如何转换列,而不是创建新列并转换另一列.
先感谢您!
我想更改Jupyter中显示的默认字体(到Gill sans),但我知道在哪里编辑它会遇到问题.
我查看了.ipython文件夹,我没有静态文件夹,我查看了.jupyter文件夹,它是空的.
有人知道吗?
我按照指南在这里:
https://plot.ly/python/filled-chord-diagram/
我制作了这个:
在指南中,我按照ribbon_info代码将hoverinfo添加到连接色带但没有显示.我可以让hoverinfo只显示功能区结束.任何人都可以看到我错在哪里?
ribbon_info=[]
for k in range(L):
sigma=idx_sort[k]
sigma_inv=invPerm(sigma)
for j in range(k, L):
if matrix[k][j]==0 and matrix[j][k]==0: continue
eta=idx_sort[j]
eta_inv=invPerm(eta)
l=ribbon_ends[k][sigma_inv[j]]
if j==k:
layout['shapes'].append(make_self_rel(l, 'rgb(175,175,175)' ,
ideo_colors[k], radius=radii_sribb[k]))
z=0.9*np.exp(1j*(l[0]+l[1])/2)
#the text below will be displayed when hovering the mouse over the ribbon
text=labels[k]+' appears on'+ '{:d}'.format(matrix[k][k])+' of the same grants as '+ '',
ribbon_info.append(Scatter(x=z.real,
y=z.imag,
mode='markers',
marker=Marker(size=5, color=ideo_colors[k]),
text=text,
hoverinfo='text'
)
)
else:
r=ribbon_ends[j][eta_inv[k]]
zi=0.9*np.exp(1j*(l[0]+l[1])/2)
zf=0.9*np.exp(1j*(r[0]+r[1])/2)
#texti and textf are the strings that will be …Run Code Online (Sandbox Code Playgroud) 只是好奇'where'的行为以及为什么要在'loc'上使用它.
如果我创建一个数据帧:
df = pd.DataFrame({'ID':[1,2,3,4,5,6,7,8,9,10],
'Run Distance':[234,35,77,787,243,5435,775,123,355,123],
'Goals':[12,23,56,7,8,0,4,2,1,34],
'Gender':['m','m','m','f','f','m','f','m','f','m']})
Run Code Online (Sandbox Code Playgroud)
然后应用'where'功能:
df2 = df.where(df['Goals']>10)
Run Code Online (Sandbox Code Playgroud)
我得到以下内容,过滤掉Goals> 10的结果,但将其他所有内容保留为NaN:
Gender Goals ID Run Distance
0 m 12.0 1.0 234.0
1 m 23.0 2.0 35.0
2 m 56.0 3.0 77.0
3 NaN NaN NaN NaN
4 NaN NaN NaN NaN
5 NaN NaN NaN NaN
6 NaN NaN NaN NaN
7 NaN NaN NaN NaN
8 NaN NaN NaN NaN
9 m 34.0 10.0 123.0
Run Code Online (Sandbox Code Playgroud)
但是,如果我使用'loc'功能:
df2 = df.loc[df['Goals']>10]
Run Code Online (Sandbox Code Playgroud)
它返回没有NaN值的子集的数据帧:
Gender Goals ID Run Distance …Run Code Online (Sandbox Code Playgroud) 我目前正在使用MS Access生成报告,但我需要做的一些计算有些限制.
我正在考虑使用Python来运行报告,即每行数据一个报告,它接受列字段并将它们放在文本框中,如下所示:
如何通过Python实现这一目标?
我试图从列表中删除 'nan',但它拒绝去。我已经尝试过 np.nan 和 'nan'。
这是我的代码:
ztt = []
for i in z:
if i != 'nan':
ztt.append(i)
ztt
Run Code Online (Sandbox Code Playgroud)
或者:
ztt = []
for i in z:
if i != np.nan:
ztt.append(i)
ztt
Run Code Online (Sandbox Code Playgroud)
我仍然得到输出:
[[46.0, 34.0, 32.0, 40.0, 34.0, 29.0, 38.0, 39.0, 45.0, 32.0, 28.0, 43.0],
[32.0, 30.0, 67.0, 66.0, 28.0, 19.0, 39.0, 32.0, 51.0, 28.0, 20.0, 36.0],
[29.0, 24.0, 37.0, 31.0, 32.0, 34.0, 28.0, 31.0, 28.0, 33.0, 28.0, 39.0],
[27.0, 29.0, 35.0, nan, nan, nan, nan, nan, nan, nan, …Run Code Online (Sandbox Code Playgroud) 我有一份在Jupyter Notebook中创建的报告。我出于审美原因希望将输出(图)居中。
我已经尝试过这里给出的答案:
但是,这不起作用。
我确实发现这可以在Stackoverflow上工作(ipython Notebook中的居中对齐输出)
CSS = """
.output {
align-items: center;
}
"""
HTML('<style>{}</style>'.format(CSS))
Run Code Online (Sandbox Code Playgroud)
但是,虽然它使图居中,但当图宽且不需要居中时,它会扩展它并使它比我不需要的页面更宽。我已经尝试过像上面说的那样调整输出边距区域,但是它要么将其再次推到左侧,要么将其挤压到需要滚动条的位置(再次,我不想这么做)
任何人有任何建议吗?我认为这将是标准且容易的,但显然不是(如果无法实现,仅将代码块居中的方法将是一个完美的解决方法?)
即此表的中心:
这是由以下代码产生的:
df = pd.DataFrame(a01)
new_df01 = df[['Call','FirstReceivedDate','Value']]
new_df01['month'] = pd.Categorical(new_df01['FirstReceivedDate'].dt.strftime('%b'),
categories=vals, ordered=True)
groupA01 = new_df01.groupby(['Call']).agg({'Value':sum, 'FirstReceivedDate':'count'}).rename(columns={'FirstReceivedDate':'Count'})
groupA01['Value'] = groupA01['Value'].map('{:,.2f}'.format)
def hover(hover_color="#F1C40F"):
return dict(selector="tr:hover",
props=[("background-color", "%s" % hover_color)])
styles2 = [
hover(),
dict(selector="th", props=[("font-size", "80%"),
("font-family", "Gill Sans MT"),
("color",'white'),
('background-color', 'rgb(11, 48, 79)'),
("text-align", "center")]),
dict(selector="td", props=[("font-size", "75%"),
("font-family", "Gill Sans MT"),
("text-align", "center")]),
dict(selector="tr", props=[("line-height", "11px")]), …Run Code Online (Sandbox Code Playgroud) 我正在使用以下代码将数据框复制到 Excel 文档中:
dfPol.to_excel(writer, 'Influence on Policy', columns=colsPol)
Run Code Online (Sandbox Code Playgroud)
问题是我收到以下错误,因为 URL 太长:
Ignoring URL .... 255 characters since it exceeds Excel's limit for URLS
Run Code Online (Sandbox Code Playgroud)
所以,我找到了一个使用的解决方案:
dfPol.to_excel(writer, 'Influence on Policy', columns=colsPol, options={'strings_to_urls': False})
Run Code Online (Sandbox Code Playgroud)
但我收到以下错误:
TypeError: to_excel() got an unexpected keyword argument 'options'
Run Code Online (Sandbox Code Playgroud)
显然 options 不适用于to_excel,这是我在脚本中用于许多其他代码的内容(即我想坚持使用 'to_excel')
我的问题有什么解决方案吗?
这不是重复:How to save in *.xlsx long URL in cell using Pandas as that is not about to_excel (it is about excelwriter)
我有以下代码:
import pyodbc
conn = pyodbc.connect('DSN=QueryBuilder')
cursor = conn.cursor()
stringA = "SELECT GrantInformation.Call FROM GrantInformation"
cursor.execute(stringA)
rows = cursor.fetchall()
Run Code Online (Sandbox Code Playgroud)
它运作良好多年,但突然间它已经停止了今天的工作与以下追溯:
Traceback (most recent call last):
File "C:/Users/nicholas/Desktop/test.py", line 6, in <module>
cursor = conn.cursor()
AttributeError: 'NoneType' object has no attribute 'cursor'
Run Code Online (Sandbox Code Playgroud)
该代码仍可在Jupyter Notebook中使用,但不再适用于Pycharm/IDLE
如果我在Pycharm中运行:
print(pyodbc.dataSources())
print(pyodbc.drivers())
Run Code Online (Sandbox Code Playgroud)
我明白了:
none
none
Run Code Online (Sandbox Code Playgroud)
如果我在Jupyter Notebook中这样做,我得到:
{'Visio Database Samples': 'Microsoft Access Driver (*.mdb, *.accdb)', 'dBASE Files': 'Microsoft Access dBASE Driver (*.dbf, *.ndx, *.mdx)', 'Excel Files': 'Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)', 'MS Access Database': …Run Code Online (Sandbox Code Playgroud)