小编ReK*_*eKx的帖子

将YAML文件转换为Python JSON对象

如何加载YAML文件并将其转换为Python JSON对象?

我的YAML文件如下所示:

Section:
    heading: Heading 1
    font: 
        name: Times New Roman
        size: 22
        color_theme: ACCENT_2

SubSection:
    heading: Heading 3
    font:
        name: Times New Roman
        size: 15
        color_theme: ACCENT_2
Paragraph:
    font:
        name: Times New Roman
        size: 11
        color_theme: ACCENT_2
Table:
    style: MediumGrid3-Accent2
Run Code Online (Sandbox Code Playgroud)

python json yaml python-3.x

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

使用python-docx创建页眉和页脚

是否有在Microsoft Word(docx)文件中添加页眉和页脚的解决方法?

提供的头实现python-docx仍在开发中.

更具体地说,我想补充一下:

  1. 页脚到页脚
  2. 一些随机文本到标题

理想的代码如下所示:

from docx import Document

document = Document()

# Add header and footer on all pages

document.save("demo.docx")
Run Code Online (Sandbox Code Playgroud)

python header footer python-3.x python-docx

9
推荐指数
2
解决办法
4380
查看次数

如何根据行值获取pandas中的列名?

我有一个数据帧,df:

        id_0         id_1          id_2
0         1            0             1
1         1            0             0
2         0            1             0
3         1            1             0
4         0            0             1
5         0            0             0
Run Code Online (Sandbox Code Playgroud)

我想获得每行的列名称,如果有1.如何做到这一点?谢谢.

结果:

           result
0         id_0, id_2
1         id_0
2         id_1
3         id_0, id_1
4         id_2
5         NaN
Run Code Online (Sandbox Code Playgroud)

python dataframe pandas

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

使用 pandas 从 Excel 读取下拉值

我有一个带有下拉单元格的 Excel。我一直在尝试读取 Excel 下拉列表,但它只读取所选选项。

在此输入图像描述

import pandas

df = pandas.read_excel("BQA.xlsx", header=0)
df.columns = df.columns.str.strip()

print(df)
Run Code Online (Sandbox Code Playgroud)

输出:

 Empty DataFrame
 Columns: [Column 1, Column 2, Column 3, Column 4, yes]
 Index: []
Run Code Online (Sandbox Code Playgroud)

预期输出:

Empty DataFrame
Columns: [Column 1, Column 2, Column 3, Column 4, [yes, no, yes1, no1]]
Index: []
Run Code Online (Sandbox Code Playgroud)

python excel xlsx python-3.x pandas

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

如何在python docx中更改句子的字体样式

我们如何将字体名称、大小等应用于 python docx 中的 add_run()。
我已经尝试了以下但它不起作用。

run = Document().add_paragraph().add_run()
font = run.font
font.name = “MS Gothic”
Document().add_paragraph().add_run(“Some random text”)
Run Code Online (Sandbox Code Playgroud)

python docx python-3.x python-docx

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

Pandas:dataframe cumsum,如果其他列为false则重置

我有一个包含2列的数据框,这里的目标很简单; 如果行列设置为False,则重置df.cumsum();

DF

      value      condition
0       1            1
1       2            1
2       3            1
3       4            0
4       5            1
Run Code Online (Sandbox Code Playgroud)

想要的结果如下:

DF

      value      condition
0       1            1
1       3            1
2       6            1
3       4            0
4       9            1
Run Code Online (Sandbox Code Playgroud)

如果我循环数据帧,如本文所述Python pandas cumsum()重置后达到最大值 我可以实现想要的结果,但我正在寻找一个更加矢量化的方式使用pandas标准函数

numpy dataframe pandas cumsum

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

标签 统计

python ×5

python-3.x ×4

pandas ×3

dataframe ×2

python-docx ×2

cumsum ×1

docx ×1

excel ×1

footer ×1

header ×1

json ×1

numpy ×1

xlsx ×1

yaml ×1