小编Big*_*Ben的帖子

熊猫模式='a',if_sheet_exists='overlay'不起作用

即使使用下面的代码,.xlsx 文件每张纸上的内容也会被覆盖,而不是附加。缺什么?

\n
writer = pd.ExcelWriter(excelfilepath, engine='openpyxl', mode='a', if_sheet_exists='overlay')\n\ndf1.to_excel(writer, sheet_name='N\xc3\xbacleo de TRIAGEM')\n\ndf2.to_excel(writer, sheet_name='N\xc3\xbacleo de FAL\xc3\x8aNCIAS')\n\ndf3.to_excel(writer, sheet_name='RE - Triagem')\n\ndf4.to_excel(writer, sheet_name='RE - Fal\xc3\xaancias')\n\nwriter.save()\n
Run Code Online (Sandbox Code Playgroud)\n

python excel xlsx pandas

15
推荐指数
2
解决办法
1万
查看次数

Seaborn jointplot 关闭边缘图之一

有没有办法关闭 Seaborn Jointplot 中的顶部边缘图?

tips = sns.load_dataset('tips')
g = sns.jointplot(
    data=tips,
    x="total_bill",
    y="tip",
    hue="smoker",
)
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

python seaborn

8
推荐指数
1
解决办法
2186
查看次数

Plotly:找不到 mimetype“application/vnd.plotly.v1+json”的渲染器

环境:

  • 视觉代码
  • Jupyter 扩展 (v2022.9.1202862440)
  • 内核:Python 3.10.1 64位
  • pyplot 版本:5.10.0
  • Nb格式版本:5.7.0

发生了什么?

我正在尝试通过以下代码使用简单的箱线图plotly.express

#Basic vizualization
fig = px.box(dataset, y='Rh2')
fig.update_layout(
    height=1000
)
Run Code Online (Sandbox Code Playgroud)

第一个错误非常简单:ValueError: Mime type rendering requires nbformat>=4.2.0 but it is not installed我使用此答案解决了该错误。

第二个错误是我现在遇到的错误:

No renderer could be found for mimetype "application/vnd.plotly.v1+json", but one might be available on the Marketplace.
Run Code Online (Sandbox Code Playgroud)

我不知道在这里可以做什么 - 在互联网上没有提到这样的问题(至少我找不到任何)+市场空间也没有帮助!

提前致谢


编辑:

尝试添加:pio.renderers.default = "vscode"和其他各种内容,但它们不会导致错误,只是空白。

python pandas plotly nbformat

8
推荐指数
1
解决办法
3464
查看次数

独立移动数组中的行

我想按行号移动每一行,并与我想要的输出形状相关。一个例子:

array([[0, 1, 2],        array([[0, 1, 2],                array([[0, 1, 2, 0, 0],
       [1, 2, 3],    ->            [1, 2, 3],      ->            [0, 1, 2, 3, 0],
       [2, 3, 4]])                    [2, 3, 4]])                [0, 0, 2, 3, 4])
Run Code Online (Sandbox Code Playgroud)

最左边的数组是我的输入,最右边的数组是我想要的输出。这可以推广到更大的数组,例如10x10数组。

有没有很好的方法来做到这一点?


我所拥有的是:

A = np.array([[1, 2, 3],
              [2, 3, 4],
              [3, 4, 5]], dtype=np.float32)

out = np.zeros((A.shape[0], A.shape[1]*2-1))

out[[np.r_[:3]], [np.r_[:3] + np.r_[:3][:,None]]] = A
Run Code Online (Sandbox Code Playgroud)

python arrays numpy

6
推荐指数
1
解决办法
102
查看次数

AttributeError:“AxesSubplot”对象没有属性“set_color_cycle”

我试图通过以下代码设置颜色周期:

fig, axes = plt.subplots(1, 2, figsize=(20, 8.5))
plt.subplots_adjust(wspace=0.09, hspace=0.09)
axes[0].set_color_cycle(['#00FFFF','#0000FF','#DC143C' , '#A52A2A','#7FFF00','#8A2BE2','#000000','#D2691E',\
                           '#008B8B','#B8860B', '#006400', '#FF8C00','#8B0000','#2F4F4F','#FF1493','#FFD700',\
                           '#00FF00','#BA55D3', '#FF4500', '#800080'])
Run Code Online (Sandbox Code Playgroud)

然而,它弹出

“AttributeError:‘AxesSubplot’对象没有属性‘set_color_cycle’”

import matplotlib as mpl, matplotlib.pyplot as plt
print(mpl.__version__)
Run Code Online (Sandbox Code Playgroud)

给出输出:3.1.1 Python 版本 - 3.7.4

python matplotlib

5
推荐指数
0
解决办法
7603
查看次数

如何使用谷歌应用程序脚本编辑器过滤列中的数据

我正面临一些与使用 google 应用程序脚本编辑器过滤列中的数据相关的问题。

在此处输入图片说明

正如您在上面的屏幕截图中看到的那样,我可以使用 google 应用程序脚本在列中设置过滤器。但问题是当我试图获取过滤后的数据时。它返回一些数字系列而不是实际数据,如下所示:

[20-03-09 18:19:48:395 IST] [1,2,4,5,6,8,9,10,11,12,13,14,15,19,20,21,22,23,24,26,27,28,29,30]

Run Code Online (Sandbox Code Playgroud)

设置过滤器:

function setFilter() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();

  var filterSettings = {};

  // The range of data on which you want to apply the filter.
  // optional arguments: startRowIndex, startColumnIndex, endRowIndex, endColumnIndex
  filterSettings.range = {
    sheetId: ss.getActiveSheet().getSheetId()
  };

  // Criteria for showing/hiding rows in a filter
  // https://developers.google.com/sheets/api/reference/rest/v4/FilterCriteria
  filterSettings.criteria = {};
  var columnIndex = 2;
  filterSettings['criteria'][columnIndex] = {
    'hiddenValues': ["England", "France"]
  };

  var request = {
    "setBasicFilter": {
      "filter": filterSettings …
Run Code Online (Sandbox Code Playgroud)

google-sheets google-apps-script google-sheets-api

5
推荐指数
1
解决办法
2738
查看次数

使用VBA“With”语句来引用对象本身?

如果我在 VBA 中使用“With”关键字,则必须访问“With”锁定的对象中的属性/方法。但是,我可以在“With”语句中引用对象本身吗?

Fe,假设我有一个函数接受一个范围作为输入。我还将“With”锁定在特定范围内,以便编辑该范围内的多个属性:

Function ViewCellColor(inputrange As Range)
    ' This function takes a range as input
    MsgBox inputrange.Interior.Color
End Function

Sub Test()
    With Range("A1")
        .Select
        .Interior.Color = vbRed
        .Value = 10
        .Font.Bold = True
        Run ViewCellColor(Range("A1")) ' Use range as input to function
    End With
End Sub
Run Code Online (Sandbox Code Playgroud)

在这里,我想将范围本身传递给函数,但我必须重写范围引用(A1)以用于函数参数传递。是否可以避免在此处重复输入范围引用?

excel vba

5
推荐指数
1
解决办法
1861
查看次数

拆分以竖线分隔的系列,按单独的系列分组,并在新列中返回每个拆分值的计数

给定一个带有竖线分隔系列的数据框:

import pandas as pd
import matplotlib.pyplot as plt

df = pd.DataFrame({'year': [1960, 1960, 1961, 1961, 1961],
                   'genre': ['Drama|Romance|Thriller',
                             'Spy|Mystery|Bio',
                             'Drama|Romance',
                             'Drama|Romance',
                             'Drama|Spy']})
Run Code Online (Sandbox Code Playgroud)

或以数据格式:

   year                   genre
0  1960  Drama|Romance|Thriller
1  1960         Spy|Mystery|Bio
2  1961           Drama|Romance
3  1961           Drama|Romance
4  1961               Drama|Spy
Run Code Online (Sandbox Code Playgroud)

我可以将genre系列拆分为str.split(如关于 SO 的许多类似问题所示)。

但是,我也想在今年组和返回的计数DramaRomanceThriller,等了新列,每列特殊的一年。

我的初步尝试:

df_split = df.groupby('year')['genre'].apply(lambda x: x.str.split('|', expand=True).reset_index(drop=True))
Run Code Online (Sandbox Code Playgroud)

返回

            0        1         2
year                            
1960 0  Drama  Romance  Thriller
     1    Spy  Mystery       Bio
1961 0  Drama  Romance …
Run Code Online (Sandbox Code Playgroud)

python matplotlib pandas

5
推荐指数
1
解决办法
185
查看次数

如何在 Python 中使用 Bokeh 查看 Holoviews 的选项

一直在使用holoview来生成一些整洁的图。我想看看hv.Curve当我使用 opts 时我有什么选择。几乎没有文档。holoview帮助页面没有帮助。其中说“对于完整的文档以及可用的样式和绘图选项,请使用hv.help(hv.Curve).”。然而,它没有解释如何使用它。我试过将它作为代码的一部分运行。我试过在我的终端中运行命令。我已经尝试过print(),并与help(). 我只想知道我可以在这里放什么:overlay.opts(legend_position='right')除了legend_position?这是我试图让hv.help(hv.Curve)命令工作的代码。我知道这很可笑:

#!/usr/bin/env python3

import holoviews as hv
import numpy as np
import scipy.special
import pandas as pd
import bokeh
import pandas as pd
import numpy as np
import bokeh as bk
import plotly.graph_objects as go
import plotly.express as pex
import holoviews.plotting.bokeh
import numpy as np
import pandas as pd
from holoviews import *
from holoviews import Store …
Run Code Online (Sandbox Code Playgroud)

python python-3.x bokeh holoviews

5
推荐指数
1
解决办法
677
查看次数

如何使用 LibreOffice 的 RIGHT 函数获取某个字符后面的子字符串?

在单元格中A2,我有一个姓氏,AARY后跟一个左括号和一个名字(Max

\n

\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0|\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\ xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0A\xc2\xa0\xc2\xa0\xc2\xa0\xc2\ xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\ xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\ xa0\xc2\xa0|\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0 \xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2 \xa0B\n
\n-------------------------------------------------------- ----------------------
\n1 \xc2\xa0\xc2\xa0\xc2\xa0|\xc2\xa0\xc2\xa0\xc2\xa0 最后艺术家姓名 \xc2\xa0\xc2\xa0\xc2\xa0|\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\ xc2\xa0 艺术家的名字
\n---------------------------------------- --------------------------
\n2 \xc2\xa0\xc2\xa0\xc2\xa0|\xc2\xa0\xc2\xa0\ xc2\xa0 AARY(最大\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0 \xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0|\xc2\xa0这里名字是“Max”

\n
\n

我想使用命令提取不带括号的名字

=RIGHT(A2,LEN(A2)-SEARCH("(",A2))

但在括号中出现错误Err:508

\n

当我在公式末尾添加括号时,我得到LibreOffice Calc found an error in the formula entered.

\n

为什么会发生这种情况?

\n

libreoffice

5
推荐指数
1
解决办法
4829
查看次数