小编Sim*_*ink的帖子

如何在树状图上添加 % 信息?

我正在绘制树形图,想知道如何绘制树类的相对百分比,即

A 组 =100
组 B =30
组 C =50
组 D =20

然后,在图中,它应该 在其“X 组”标签旁边添加:“
50%”用于 A 组,“
15%”用于 B 组
等。鉴于此代码,我将如何做到这一点?

!pip install squarify
import squarify 
df = pd.DataFrame({'customers':[8,3,4,2], 'cluster':["group A", "group B", "group C", "group D"] })
squarify.plot(sizes=df['customers'], label=df['cluster'], alpha=.8 )
plt.axis('off')
plt.show();
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

python python-3.x squarify

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

Remove an element from nested lists with mixed structures (lists and integers) in Python

Consider the lists:

assigned = [4,8]
matching = [['B', [4, 5, 6]], ['C', [7, 8, 9]]]
Run Code Online (Sandbox Code Playgroud)

I am trying to remove given integers with the following code

for ii in range(len(assigned)):
    while any(assigned[ii] in x for x in matching):
        matching.remove(assigned[ii])
Run Code Online (Sandbox Code Playgroud)

I have two problems here. First one is to get into the inner lists. Right now the code does nothing because there is no matching.

Second problem, I tried this:

t = ['B', [4, 5, 6]]
if any(4 in x …
Run Code Online (Sandbox Code Playgroud)

python nested-lists

4
推荐指数
1
解决办法
59
查看次数

git status 显示未跟踪的文件,尽管被忽略

.gitignore我的存储库中的文件中有一些条目git,但某些条目仍然显示为未跟踪的文件。

我的文件中的重要部分.gitignore

# IDE settings
.idea/

# Environments
win_venv/

# Byte-compiled / optimized / DLL files
__pycache__/

# Distribution / packaging
*.egg-info/
Run Code Online (Sandbox Code Playgroud)

但是,当我运行时git status,会出现以下情况:

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        .idea/
        mypackage.egg-info/
        mypackage/__pycache__/
        mypackage/schema/__pycache__/
        mypackage/schema/models/__pycache__/
        mypackage/tests/__pycache__/
        win_venv/
Run Code Online (Sandbox Code Playgroud)

有人知道为什么会发生这种情况或者我的.gitignore文件中有什么错误吗?

这个问题与建议的答案不同,因为所示的文件未被跟踪。venv如果我创建一个新的虚拟环境,并在文件中包含适当的条目,也会发生此问题.gitignore

git

4
推荐指数
1
解决办法
2553
查看次数

用Pythonic方法用相同大小的数组替换nan子数组

假设我给了numpy这样一个数组:

a = np.array([1, 2, 3, 4, np.nan, 5, np.nan, 6, np.nan])
# [1, 2, 3, 4, nan, 5, nan, 6, nan]
Run Code Online (Sandbox Code Playgroud)

我知道nan数组中值的数量,并有相应的数组进行替换,例如:

b = np.array([12, 13, 14])
# [12, 13, 14]
Run Code Online (Sandbox Code Playgroud)

将数组替换b为所有nan值的pythonic 方法是什么,以便获得结果:

[1, 2, 3, 4, 12, 5, 13, 6, 14]
Run Code Online (Sandbox Code Playgroud)

python numpy

3
推荐指数
1
解决办法
36
查看次数

如何缩小 git LFS 存储库

在我的公司,我们使用git LFS存储系统开发相关的文件。该存储库包含 CAD 数据、图像、文档(*.pdf、*.docx、*.xlsx)等。绝对有必要将所有文件置于版本控制之下。然而,尽管 LFS 跟踪所有文件,但存储库的使用方式最终导致存储库的总大小达到 8GB。

基本上所有内容都被推送到主分支上,这似乎使 LFS 存储变得过时,因为无法修剪任何内容来保存本地存储。

问题

有没有办法让更多的本地对象被追溯修剪?

git git-lfs

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

如果字符串包含 [] 或 {}、() 等一组字符的通配符,如何将字符串转换为列表

我有一个这样的字符串

s = 'a,s,[c,f],[f,t]'
Run Code Online (Sandbox Code Playgroud)

我想将其转换为列表

S = ['a','s',['c','f'],['f','t']]
Run Code Online (Sandbox Code Playgroud)

我尝试使用 strip()

d = s.strip('][').split(',')
Run Code Online (Sandbox Code Playgroud)

但它没有给我想要的输出:

output = ['a', 's', '[c', 'f]', '[f', 't']
Run Code Online (Sandbox Code Playgroud)

python string list-comprehension list

0
推荐指数
1
解决办法
68
查看次数