我想在Jupyter笔记本中查看图像.这是一个9.9MB的.png文件.
from IPython.display import Image
Image(filename='path_to_image/image.png')
Run Code Online (Sandbox Code Playgroud)
我得到以下错误:
IOPub data rate exceeded.
The notebook server will temporarily stop sending output
to the client in order to avoid crashing it.
Run Code Online (Sandbox Code Playgroud)
有点令人惊讶并在别处报道.
这是预期的,有一个简单的解决方案吗?
(错误消息建议更改限制--NotebookApp.iopub_data_rate_limit.)
我想查询PostgreSQL数据库并将输出作为Pandas数据帧返回.
我使用'SqlAlchemy'创建了与数据库的连接:
from sqlalchemy import create_engine
engine = create_engine('postgresql://user@localhost:5432/mydb')
Run Code Online (Sandbox Code Playgroud)
我将Pandas数据帧写入数据库表:
i=pd.read_csv(path)
i.to_sql('Stat_Table',engine,if_exists='replace')
Run Code Online (Sandbox Code Playgroud)
根据文档,看起来pd.read_sql_query()应该接受SQLAlchemy引擎:
a=pd.read_sql_query('select * from Stat_Table',con=engine)
Run Code Online (Sandbox Code Playgroud)
但它抛出一个错误:
ProgrammingError: (ProgrammingError) relation "stat_table" does not exist
Run Code Online (Sandbox Code Playgroud)
我正在使用Pandas版本0.14.1.
这样做的正确方法是什么?
在pyspark中运行一个简单的应用程序.
f = sc.textFile("README.md")
wc = f.flatMap(lambda x: x.split(' ')).map(lambda x: (x, 1)).reduceByKey(add)
Run Code Online (Sandbox Code Playgroud)
我想使用foreach操作查看RDD内容:
wc.foreach(print)
Run Code Online (Sandbox Code Playgroud)
这会引发语法错误:
SyntaxError: invalid syntax
Run Code Online (Sandbox Code Playgroud)
我错过了什么?
我有一个pandas数据帧,df.
我想选择在所有指数df是不是在列表中,blacklist.
现在,我使用list comprehension创建所需的标签以进行切片.
ix=[i for i in df.index if i not in blacklist]
df_select=df.loc[ix]
Run Code Online (Sandbox Code Playgroud)
工作正常,但如果我需要经常这样做可能会很笨拙.
有一个更好的方法吗?
我通常得到这样的PCA负载:
pca = PCA(n_components=2)
X_t = pca.fit(X).transform(X)
loadings = pca.components_
Run Code Online (Sandbox Code Playgroud)
如果我PCA使用scikit-learnpipline 运行...
from sklearn.pipeline import Pipeline
pipeline = Pipeline(steps=[
('scaling',StandardScaler()),
('pca',PCA(n_components=2))
])
X_t=pipeline.fit_transform(X)
Run Code Online (Sandbox Code Playgroud)
......有可能获得负荷吗?
只是尝试loadings = pipeline.components_失败:
AttributeError: 'Pipeline' object has no attribute 'components_'
Run Code Online (Sandbox Code Playgroud)
谢谢!
(也有兴趣coef_从学习管道中提取属性.)
我想将Pandas数据帧附加到名为"NewTable"的sqlite数据库中的现有表中.NewTable有三个字段(ID,Name,Age),ID是主键.我的数据库连接:
import sqlite3
DB='<path>'
conn = sqlite3.connect(DB)
Run Code Online (Sandbox Code Playgroud)
我要附加的数据框:
test=pd.DataFrame(columns=['ID','Name','Age'])
test.loc[0,:]='L1','John',17
test.loc[1,:]='L11','Joe',30
Run Code Online (Sandbox Code Playgroud)
如上所述,ID是NewTable中的主键.键'L1'已经在NewTable中,但键'L11'不在.我尝试将数据框附加到NewTable.
from pandas.io import sql
sql.write_frame(test,name='NewTable',con=conn,if_exists='append')
Run Code Online (Sandbox Code Playgroud)
这会引发错误:
IntegrityError: column ID is not unique
Run Code Online (Sandbox Code Playgroud)
错误可能是键'L1'已经在NewTable中.数据框中的任何条目都不会附加到NewTable.但是,我可以毫无问题地将具有新密钥的数据帧附加到NewTable.
是否有一种简单的方法(例如,没有循环)将Pandas数据帧附加到sqlite表,以便附加数据帧中的新键,但表中已存在的键不是?
谢谢.
我有一个带有单列字符串的 Pandas 数据框。我想将列数据转换为浮动。由于格式的原因,某些值无法转换为浮点数。我想从结果中省略这些“非法字符串”,只提取可以合法地重新转换为浮点数的值。起始数据:
test=pd.DataFrame()
test.loc[0,'Value']='<3'
test.loc[1,'Value']='10'
test.loc[2,'Value']='Detected'
test.loc[3,'Value']=''
Run Code Online (Sandbox Code Playgroud)
所需的输出仅包含可以重新转换为浮点数的字符串(在本例中为 10):
cleanDF=test['Value'].astype(float)
cleanDF
0 10
Name: Value, dtype: float64
Run Code Online (Sandbox Code Playgroud)
当然,这会在浮点转换的非法字符串上按预期抛出错误:
ValueError: could not convert string to float: <3
Run Code Online (Sandbox Code Playgroud)
如果数据框很大并且“值”中包含许多非法字符串,是否有一种简单的方法可以解决这个问题?
谢谢。
我将链接嵌入到Pandas数据框的一列(下表)中,并将该数据框写入hmtl。
数据框表中的链接的格式如下所示(索引表中的第一个链接):
In: table.loc[0,'Links']
Out: u'<a href="http://xxx.xx.xxx.xxx/browser/I6.html">I6</a>'
Run Code Online (Sandbox Code Playgroud)
如果我查看(而不是索引特定的行)数据框(在笔记本中),则链接文本将被截断:
<a href="http://xxx.xx.xxx.xxx/browser/I6.html...
Run Code Online (Sandbox Code Playgroud)
我将数据框写入html:
table_1=table.to_html(classes='table',index=False,escape=False)
Run Code Online (Sandbox Code Playgroud)
但是,截断的链接(而不是全文)被写入html表:
<td> <a href="http://xxx.xx.xxx.xxx/browser/I6.html...</td>\n
Run Code Online (Sandbox Code Playgroud)
我可能需要to_html()的附加参数。
现在查看文档,但建议:
http://pandas.pydata.org/pandas-docs/dev/generated/pandas.DataFrame.to_html.html
谢谢!
我在CentOS上设置了Postgres数据库服务器,并创建了一个数据库mydb。
我psql以系统用户身份访问postgres并检查它是否存在:
$ sudo -u postgres -i
$ psql
postgres=# \l
Name | Owner | ...
--------------------
mydb | postgres | ...
Run Code Online (Sandbox Code Playgroud)
然后配置它:
(1)listen_addresses = 'localhost'在中未注释postgresql.conf。
(2)设置用户密码postgres。
sudo -u postgres psql template1
ALTER USER postgres with encrypted password 'my_password';
Run Code Online (Sandbox Code Playgroud)
但是,通过psql -U postgres -h localhost和Pgadm3的连接失败,并显示以下错误:
Ident autentication failed for user "postgres"
Run Code Online (Sandbox Code Playgroud)
我查了一下/var/lib/pgsql/9.4/data/pg_hba.conf。
ident是本地IPv6和IPv4连接的默认方法。
我将其从更改ident为md5。
然后,通过Pgadmi3连接并按psql …
我正在使用TensorBoard来可视化网络指标和图表.
我创建一个会话sess = tf.InteractiveSession()并在Jupyter笔记本中构建图形.
在图中,我包含两个摘要标量:
with tf.variable_scope('summary') as scope:
loss_summary = tf.summary.scalar('Loss', cross_entropy)
train_accuracy_summary = tf.summary.scalar('Train_accuracy', accuracy)
Run Code Online (Sandbox Code Playgroud)
然后我创建summary_writer = tf.summary.FileWriter(logdir, sess.graph)并运行:
_,loss_sum,train_accuracy_sum=sess.run([...],feed_dict=feed_dict)
我写了指标:
summary_writer.add_summary(loss_sum, i)
summary_writer.add_summary(train_accuracy_sum, i)
Run Code Online (Sandbox Code Playgroud)
我运行代码三次.
每次运行时,我都会重新导入TF并创建一个新的交互式会话.
但是,在Tensorboard中,为每次运行创建一个单独的标量窗口:
此外,如果我检查上次运行的数据,图表似乎是重复的:
每次运行时如何防止重复图形和标量窗口?
C++的xeus-cling Jupyter 内核看起来很棒。
根据安装:
xeus-cling has been packaged for the conda package manager on the linux platform.
这也适用于mac吗?
(点评线程Hacker News上表明,它不会,所以我想确认。)
如果没有,是否有其他适用于 mac 的 Jupyter C++ 内核?
python ×7
pandas ×5
jupyter ×2
postgresql ×2
apache-spark ×1
c++ ×1
html ×1
ipython ×1
neuraxle ×1
scikit-learn ×1
sqlalchemy ×1
sqlite ×1
tensorboard ×1
tensorflow ×1