该pandas drop_duplicates功能非常适合"统一"数据帧.但是,要传递的关键字参数之一是take_last=True或take_last=False,虽然我想删除列的子集中所有重复的行.这可能吗?
A B C
0 foo 0 A
1 foo 1 A
2 foo 1 B
3 bar 1 A
Run Code Online (Sandbox Code Playgroud)
作为一个例子,我想下降匹配列的行A和C所以这应该丢弃的行0和1.
我正在聚集大约100条记录的样本(未标记)并尝试使用grid_search来评估具有各种超参数的聚类算法.我正在使用得分silhouette_score很好.
在这里,我的问题是,我并不需要使用的交叉验证方面GridSearchCV/ RandomizedSearchCV,但我不能找到一个简单GridSearch/ RandomizedSearch.我可以写我自己,但ParameterSampler和ParameterGrid对象是非常有用的.
我的下一步将是子类化BaseSearchCV并实现我自己的_fit()方法,但认为值得问一下,有更简单的方法来做到这一点,例如通过传递一些东西到cv参数?
def silhouette_score(estimator, X):
clusters = estimator.fit_predict(X)
score = metrics.silhouette_score(distance_matrix, clusters, metric='precomputed')
return score
ca = KMeans()
param_grid = {"n_clusters": range(2, 11)}
# run randomized search
search = GridSearchCV(
ca,
param_distributions=param_dist,
n_iter=n_iter_search,
scoring=silhouette_score,
cv= # can I pass something here to only use a single fold?
)
search.fit(distance_matrix)
Run Code Online (Sandbox Code Playgroud) 是否有类似于.condarc(anaconda 4.0.0)的配置允许Jupyter配置为在本地计算机上的公司代理后面工作?
收到错误:
HTTPError: HTTP Error 407: Proxy Authentication Required
Run Code Online (Sandbox Code Playgroud) 我有这样一个公式的Excel文件:
=IF(OR(ISERROR(G16),ISERROR(G17)),X16,IF(OR(G16="xxx",G16="yyy",G16="zzz"),Y16,IF(G16="333","N\A",IF(G17="333",Z16,IF(D17="",IF((HEX2DEC(W$10)-HEX2DEC(W16))/VLOOKUP(F16,$M$36:$N$41,2,FALSE)<0,0,(HEX2DEC(W$10)-HEX2DEC(W16))/VLOOKUP(F16,$M$36:$N$41,2,FALSE)), IF((HEX2DEC(W17)-HEX2DEC(W16))/VLOOKUP(F16,$M$36:$N$41,2,FALSE)<0,0,(HEX2DEC(W17)-HEX2DEC(W16))/VLOOKUP(F16,$M$36:$N$41,2,FALSE)))))))
我想简化它们,以便以更易读的方式编写.
我有一个QListView包含一些项目.现在我想得到所选项目的索引,即如果我选择第5个元素我应该得到5.我怎么能得到这个?
我正在尝试使用该shapely.geometry.Polygon模块来查找多边形区域,但它会在xy平面上执行所有计算.这对我的一些多边形来说很好,但是其他的也有一个z维度,所以它不是我想做的.
是否有一个包可以从xyz坐标给我一个平面多边形的区域,或者一个包或算法将多边形旋转到xy平面,以便我可以使用shapely.geometry.Polygon().area?
多边形表示为表单中的元组列表[(x1,y1,z1),(x2,y2,z3),...(xn,yn,zn)].
我刚刚完成了一个Python程序的测试,该程序涉及登录到站点并需要设置CSRF cookie.我已经尝试将其打包为exe使用py2exe并出现套接字错误.我尝试时遇到同样的问题PyInstaller.谷歌搜索Errno我发现其他一些人有同样的问题,所以我知道问题是与SLL证书的位置有关.
这是我的site_agent课程,包括日志记录调用.
class site_agent:
self.get_params()
URL = root_url + '/accounts/login/'
# Retrieve the CSRF token first
self.agent = requests.session()
self.agent.get(URL) # retrieves the cookie # This line throws the error
self.csrftoken = self.agent.cookies['csrftoken']
# Set up login data including the CSRF cookie
login_data = {'username': self.username,
'password': self.password,
'csrfmiddlewaretoken' : self.csrftoken}
# Log in
logging.info('Logging in')
response = self.agent.post(URL, data=login_data, headers=hdr)
Run Code Online (Sandbox Code Playgroud)
该错误出现在该self.agent.get(URL)行,Traceback显示:
Traceback (most recent call last):
File "<string>", line 223, …Run Code Online (Sandbox Code Playgroud) 这足以重现这个问题:
另存为 test.bat
:: Create Conda env
set name=%1
conda create -n %name% python -y
activate %name%
echo "Never gets here"
:: script should continue below...
Run Code Online (Sandbox Code Playgroud)
从cmd运行.
>test.bat "testname"
Run Code Online (Sandbox Code Playgroud)
输出:
C:\Users\Jamie\git>test.bat testname
C:\Users\Jamie\git>set name=testname
C:\Users\Jamie\git>conda create -n testname python -y
Fetching package metadata ...........
Solving package specifications: .
Package plan for installation in environment C:\Users\Jamie\Miniconda2\envs\testname:
The following NEW packages will be INSTALLED:
pip: 9.0.1-py27_1
python: 2.7.13-0
setuptools: 27.2.0-py27_1
vs2008_runtime: 9.00.30729.5054-0
wheel: 0.29.0-py27_0
#
# To activate this environment, use:
# …Run Code Online (Sandbox Code Playgroud) 我有一个表,用于为客户端定义默认和自定义选项。如果该custom_id字段具有值,则它代表唯一自定义作业的记录。如果为空,则该记录代表客户端的默认选项。
我的问题是我想在两种情况下强制执行唯一性:
custom_id,client并且option都非空client且option非空,但custom_id为空下面的表定义适用于第一种情况,但不适用于第二种情况,因为 null 不被视为值。有没有办法让 null 被视为一个值?
class OptionTable(Base):
__tablename__ = "option_table"
__table_args__ = (
UniqueConstraint("custom", "client", "option", name="uix_custom_client_option"),
)
id = Column(Integer, primary_key=True)
custom_id = Column(Integer, ForeignKey("custom.id"), nullable=True)
client = Column(String, nullable=False)
option = Column(String, nullable=False)
Run Code Online (Sandbox Code Playgroud)
以下是一些示例数据以及按顺序添加它们后的结果:
+----+----------+----------+--------+---------------------------------------------+
| id | CustomID | Client | Option | result |
+----+----------+----------+--------+---------------------------------------------+
| 1 | 123 | MegaCorp | Apple | OK |
| 2 | 123 …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个水平堆叠条形图,matplotlib但是我看不到如何使条形实际堆叠而不是从y轴开始.
这是我的测试代码.
fig = plt.figure()
ax = fig.add_subplot(1,1,1)
plot_chart(df, fig, ax)
ind = arange(df.shape[0])
ax.barh(ind, df['EndUse_91_1.0'], color='#FFFF00')
ax.barh(ind, df['EndUse_91_nan'], color='#FFFF00')
ax.barh(ind, df['EndUse_80_1.0'], color='#0070C0')
ax.barh(ind, df['EndUse_80_nan'], color='#0070C0')
plt.show()
Run Code Online (Sandbox Code Playgroud)
left在看到tcaswell的评论后编辑使用kwarg.
fig = plt.figure()
ax = fig.add_subplot(1,1,1)
plot_chart(df, fig, ax)
ind = arange(df.shape[0])
ax.barh(ind, df['EndUse_91_1.0'], color='#FFFF00')
lefts = df['EndUse_91_1.0']
ax.barh(ind, df['EndUse_91_nan'], color='#FFFF00', left=lefts)
lefts = lefts + df['EndUse_91_1.0']
ax.barh(ind, df['EndUse_80_1.0'], color='#0070C0', left=lefts)
lefts = lefts + df['EndUse_91_1.0']
ax.barh(ind, df['EndUse_80_nan'], color='#0070C0', left=lefts)
plt.show()
Run Code Online (Sandbox Code Playgroud)
这似乎是正确的方法,但如果没有特定条形的数据,它会失败,因为它试图添加nan一个然后返回的值nan.
python ×7
conda ×2
pandas ×2
3d ×1
anaconda ×1
area ×1
batch-file ×1
duplicates ×1
excel ×1
excel-vba ×1
jupyter ×1
listview ×1
matplotlib ×1
miniconda ×1
nokia ×1
polygon ×1
postgresql ×1
py2exe ×1
pyinstaller ×1
qt ×1
qt4 ×1
scikit-learn ×1
scoring ×1
sqlalchemy ×1
ssl ×1
symbian ×1
vba ×1