我有一个动态的DataFrame,它工作得很好,但当没有数据要添加到DataFrame时,我得到一个错误。因此,我需要一个解决方案来创建一个只有列名的空DataFrame。

现在我有这样的东西:

df = pd.DataFrame(columns=COLUMN_NAMES) # Note that there are now row data inserted.

PS:列名仍然会出现在DataFrame中,这很重要。

但当我像这样使用它时,结果是这样的:

Index([], dtype='object')
Empty DataFrame

“空数据框架”部分很好!但我需要显示的不是索引,而是列。

我发现了一件重要的事情:我正在使用Jinja2将这个DataFrame转换为PDF,因此我调用了一个方法,首先将它输出到HTML,就像这样:

df.to_html()

我想这就是列的缺失之处。

总的来说,我遵循了这个例子:http://pbpython.com/pdf-reports.html。css也是来自链接。这就是我将数据帧发送到PDF的方法:

env = Environment(loader=FileSystemLoader('.'))
template = env.get_template("pdf_report_template.html")
template_vars = {"my_dataframe": df.to_html()}

html_out = template.render(template_vars)
HTML(string=html_out).write_pdf("my_pdf.pdf", stylesheets=["pdf_report_style.css"])

最近,我在安装SciPy时遇到了麻烦,特别是在我正在开发的Heroku应用程序上,我发现了Conda。

使用Conda可以创建环境,这与virtualenv的功能非常相似。我的问题是:

如果我使用Conda,它会取代对virtualenv的需求吗?如果不是,我如何将两者结合使用?我是在Conda中安装virtualenv,还是在virtualenv中安装Conda ? 我还需要使用pip吗?如果是这样,我还能在隔离的环境中安装带有pip的包吗?

我刚刚发现ASP中的每个请求。网络web应用程序在请求开始时获得一个会话锁,然后在请求结束时释放它!

如果你不明白这其中的含义,就像我一开始一样,这基本上意味着:

Any time an ASP.Net webpage is taking a long time to load (maybe due to a slow database call or whatever), and the user decides they want to navigate to a different page because they are tired of waiting, they can't! The ASP.Net session lock forces the new page request to wait until the original request has finished its painfully slow load. Arrrgh. Anytime an UpdatePanel is loading slowly, and the user decides to navigate to a different page before the UpdatePanel has finished updating... they can't! The ASP.Net session lock forces the new page request to wait until the original request has finished its painfully slow load. Double Arrrgh!

那么有什么选择呢?到目前为止,我想出了:

Implement a Custom SessionStateDataStore, which ASP.Net supports. I haven't found too many out there to copy, and it seems kind of high risk and easy to mess up. Keep track of all requests in progress, and if a request comes in from the same user, cancel the original request. Seems kind of extreme, but it would work (I think). Don't use Session! When I need some kind of state for the user, I could just use Cache instead, and key items on the authenticated username, or some such thing. Again seems kind of extreme.

我真不敢相信ASP。Net微软团队在4.0版本的框架中留下了如此巨大的性能瓶颈!我是不是遗漏了什么明显的东西?为会话使用ThreadSafe集合有多难?

我有以下数据框架:

> df1
  id  begin conditional confidence discoveryTechnique  
0 278    56       false        0.0                  1   
1 421    18       false        0.0                  1 

> df2
   concept 
0  A  
1  B

如何对下标进行归并得到:

  id  begin conditional confidence discoveryTechnique concept 
0 278    56       false        0.0                  1       A 
1 421    18       false        0.0                  1       B

我问是因为这是我的理解,合并()即df1.merge(df2)使用列来进行匹配。事实上,这样做我得到:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/pandas/core/frame.py", line 4618, in merge
    copy=copy, indicator=indicator)
  File "/usr/local/lib/python2.7/dist-packages/pandas/tools/merge.py", line 58, in merge
    copy=copy, indicator=indicator)
  File "/usr/local/lib/python2.7/dist-packages/pandas/tools/merge.py", line 491, in __init__
    self._validate_specification()
  File "/usr/local/lib/python2.7/dist-packages/pandas/tools/merge.py", line 812, in _validate_specification
    raise MergeError('No common columns to perform merge on')
pandas.tools.merge.MergeError: No common columns to perform merge on

在索引上合并是不好的做法吗?不可能吗?如果是这样,我如何将索引移到一个名为“index”的新列中?

我有一个名为“mydata”的数据帧,它看起来像这样:

   A  B  C   D 
1. 5  4  4   4 
2. 5  4  4   4 
3. 5  4  4   4 
4. 5  4  4   4 
5. 5  4  4   4 
6. 5  4  4   4 
7. 5  4  4   4 

我想删除第2行,第4行,第6行。例如,像这样:

   A  B  C   D
1. 5  4  4  4 
3. 5  4  4  4 
5. 5  4  4  4 
7. 5  4  4  4 

我想知道粘性会话和非粘性会话之间的区别。我从网上读到的是:

粘性:只有一个会话对象将在那里。

非会话保持:每个服务器节点的会话对象

我的web应用程序使用会话存储关于用户的信息,一旦他们登录,并维护这些信息,因为他们在应用程序内从页面到页面。在这个特定的应用程序中,我存储的人的user_id, first_name和last_name。

我想在登录时提供一个“让我登录”选项,在用户的机器上放置一个cookie,为期两周,当他们返回应用程序时,将以相同的细节重新启动他们的会话。

做这件事的最佳方法是什么?我不想在cookie中存储他们的user_id,因为这似乎会让一个用户很容易尝试和伪造另一个用户的身份。

我想打印整个数据框架,但我不想打印索引

另外,其中一列是datetime类型,我只想打印时间,而不是日期。

数据框架看起来像这样:

   User ID           Enter Time   Activity Number
0      123  2014-07-08 00:09:00              1411
1      123  2014-07-08 00:18:00               893
2      123  2014-07-08 00:49:00              1041

我要按原样打印

User ID   Enter Time   Activity Number
123         00:09:00              1411
123         00:18:00               893
123         00:49:00              1041

我使用spark-csv加载数据到一个DataFrame。我想做一个简单的查询并显示内容:

val df = sqlContext.read.format("com.databricks.spark.csv").option("header", "true").load("my.csv")
df.registerTempTable("tasks")
results = sqlContext.sql("select col from tasks");
results.show()

山坳似乎被截断了:

scala> results.show();
+--------------------+
|                 col|
+--------------------+
|2015-11-16 07:15:...|
|2015-11-16 07:15:...|
|2015-11-16 07:15:...|
|2015-11-16 07:15:...|
|2015-11-16 07:15:...|
|2015-11-16 07:15:...|
|2015-11-16 07:15:...|
|2015-11-16 07:15:...|
|2015-11-16 07:15:...|
|2015-11-16 07:15:...|
|2015-11-16 07:15:...|
|2015-11-16 07:15:...|
|2015-11-16 07:15:...|
|2015-11-16 07:15:...|
|2015-11-16 07:15:...|
|2015-11-06 07:15:...|
|2015-11-16 07:15:...|
|2015-11-16 07:21:...|
|2015-11-16 07:21:...|
|2015-11-16 07:21:...|
+--------------------+

如何显示列的全部内容?

有可能行绑定两个没有相同列集的数据帧吗?我希望保留绑定后不匹配的列。