使用羽毛包时(http://blog.cloudera.com/blog/2016/03/feather-a-fast-on-disk-format-for-data-frames-for-r-and-python-powered-通过-apache-arrow /)尝试编写一个简单的20x20数据帧,我不断收到一条错误,指出尚未支持跨步数据.我不相信我的数据是跨步的(或不同寻常的),我可以复制网站上给出的示例代码,但似乎无法让它与我自己的工作.以下是一些示例代码:
import feather
import numpy as np
import pandas as pd
tempArr = reshape(np.arange(400), (20,20))
df = pd.DataFrame(tempArr)
feather.write_dataframe(df, 'test.feather')
Run Code Online (Sandbox Code Playgroud)
最后一行返回以下错误:
FeatherError: Invalid: no support for strided data yet
Run Code Online (Sandbox Code Playgroud)
我在Ubuntu 14.04上运行它.我是否可能误解了有关熊猫数据帧的存储方式?
我们刚刚从 切换nose
到pytest
并且似乎没有抑制第三方日志记录的选项。在nose
配置中,我们有以下行:
logging-filter=-matplotlib,-chardet.charsetprober,-PIL,-fiona.env,-fiona._env
Run Code Online (Sandbox Code Playgroud)
其中一些日志非常啰嗦,尤其是matplotlib
我们不想看到输出,只想从我们的日志中输出。
但是我找不到等效的设置pytest
。是否可以?我错过了什么吗?谢谢。
有没有办法通过参数或其他东西在逻辑模型中为逻辑回归模型设置l2-Penalty?我刚刚在文档中找到了l1-Penalty,但对于l2-Penalty却没有.
嘿伙计们,我刚刚加入了python3 HypeTrain!但是我只是想知道如何在布尔值上使用if语句:示例:
RandomBool = True
#and now how can i check this in an if statement? Like the following:
if RandomBool == True:
#DoYourThing
Run Code Online (Sandbox Code Playgroud)
而且,我可以像这样切换一个布尔值吗?
RandomBool1 == True #Boolean states True
if #AnyThing:
RandomBool1 = False #Boolean states False from now on?
Run Code Online (Sandbox Code Playgroud) 给定以下数据框,如何生成条件累积总和列。
import pandas as pd
import numpy as np
data = {'D':[2015,2015,2015,2015,2016,2016,2016,2017,2017,2017], 'Q':np.arange(10)}
df = pd.DataFrame(data)
D Q
0 2015 0
1 2015 1
2 2015 2
3 2015 3
4 2016 4
5 2016 5
6 2016 6
7 2017 7
8 2017 8
9 2017 9
Run Code Online (Sandbox Code Playgroud)
累计总和将整列相加。我正在尝试弄清楚如何将np.cumsum
与条件函数一起使用。
df['Q_cum'] = np.cumsum(df.Q)
D Q Q_cum
0 2015 0 0
1 2015 1 1
2 2015 2 3
3 2015 3 6
4 2016 4 10
5 2016 5 …
Run Code Online (Sandbox Code Playgroud) 当我解决线性规划问题时,如下面的公式,我希望x all的结果是int类型
请考虑以下问题:
最小化: f = -1*x[0] + 4*x[1]
受制于:
-3*x[0] + 1*x[1] <= 6
1*x[0] + 2*x[1] <= 4
x[1] >= -3
Run Code Online (Sandbox Code Playgroud)
哪里: -inf <= x[0] <= inf
接下来是python编码器
>>> c = [-1, 4]
>>> A = [[-3, 1], [1, 2]]
>>> b = [6, 4]
>>> x0_bounds = (None, None)
>>> x1_bounds = (-3, None)
>>> res = linprog(c, A_ub=A, b_ub=b, bounds=(x0_bounds, x1_bounds),
... options={"disp": True})
>>> print(res)
Optimization terminated successfully.
Current function value: -11.428571
Iterations: 2 …
Run Code Online (Sandbox Code Playgroud) 输入时df.dtypes
,我们有类型列表.但是,是否有一种简单的方法来获得输出
{'col1': np.float32, ...}
Run Code Online (Sandbox Code Playgroud)
或者我需要自己编写一个函数?
我想为名为“Id”的数据框创建一个新列,其中值是行索引 +1。我想像下面的例子:
ID Col1 ...
0 1 a ...
1 2 b ...
2 3 c ...
Run Code Online (Sandbox Code Playgroud) 是否可以将数据帧从Apache Spark导出到feather(https://github.com/wesm/feather)文件?
在列名称中创建具有一些重复单元格值的DataFrame后:
import pandas as pd
df = pd.DataFrame({'Name': ['Will','John','John','John','Alex'],
'Payment': [15, 10, 10, 10, 15],
'Duration': [30, 15, 15, 15, 20]})
Run Code Online (Sandbox Code Playgroud)
我想继续创建另一个DataFrame,其中合并Name列中的重复值,不留下任何重复项.与此同时,我想总结约翰所做的付款价值.我继续说:
df_sum = df.groupby('Name', axis=0).sum().reset_index()
Run Code Online (Sandbox Code Playgroud)
但由于df.groupby('Name', axis=0).sum()
命令将sum函数应用于DataFrame中的每一列,因此也会处理持续时间(以分钟为单位的访问时间)列.相反,我想获得持续时间列的平均值.所以我需要使用mean()
方法,如下所示:
df_mean = df.groupby('Name', axis=0).mean().reset_index()
Run Code Online (Sandbox Code Playgroud)
但是,通过mean()
功能,付款列现在显示了John所做的平均付款金额,而不是所有付款的总和.
如何创建一个DataFrame,其中Duration值显示平均值,而Payment值显示总和?
python ×9
pandas ×7
dataframe ×2
feather ×2
apache-spark ×1
boolean ×1
if-statement ×1
logging ×1
nose ×1
numpy ×1
pytest ×1
python-2.7 ×1
python-3.x ×1
scipy ×1
statsmodels ×1