小编ali*_*ali的帖子

用于分隔 Excel 工作表的多个数据框列表

我有一个可变长度的数据框列表,我想将每个数据框列表转换为每个 Excel 表。

这是我的代码:

for i in range(1, len(dfs)):
    frames = {'sheetName_i' : dfs[i]}
for sheet, df in frames.items():
    dfs[i].to_excel(writer, index=False)
#df is the whole dataframe whereas dfs is the list of df
Run Code Online (Sandbox Code Playgroud)

我的输出中只有最后一个列表。有什么方法可以将所有列表转换为单独的 Excel 工作表?

我已使用您的建议如下:

for i, df in enumerate(dfs, 1):
   for n in group: #containe the names that I want to name the sheets amd the names equal to the number of sheets.
       df.to_excel(writer, index=False, sheet_name=n.format(i))
Run Code Online (Sandbox Code Playgroud)

Sheetnames 更改为我需要的名称。而每张表的数据都是相似的,有些数据内容被遗漏了,有些数据被合并到了一张表中,并且每张表中都重复了相同的数据。有什么办法可以得到正确的输出。

很高兴听到一些建议。非常感谢您提前。

python excel pandas

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

对dataframe中特定列的重复行求和

我想根据列B的重复行添加特定列(C,D,E,F,G).而剩余的非重复行不变.列A的输出必须是重复行的第一个索引.

我有一个数据帧如下:

A     B     C  D  E  F  G
box1  0487  1     1     1
box2  0487     1     1
blue  0478  1  1        1
gray  0478  1  1  1  1
gray  0478        1  1  1
flat  8704  1  1        1
clay  8704        1     1
dark  8740  1  1  1  1  1
late  4087  1     1     1
Run Code Online (Sandbox Code Playgroud)

我希望输出如下:

A     B     C   D  E  F  G
box1  0487  1   1  1  1  1
blue  0478  2   2  2  2  2
flat  8704  1 …
Run Code Online (Sandbox Code Playgroud)

python dataframe pandas

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

单个按钮多个事件取决于其他按钮背景tkinter

我有一个按钮(B),其功能应取决于其他按钮的单击.假设我有3个可靠的按钮(b1,b2,b3),通过点击它可以改变背景.我使用以下命令为3个按钮更改背景颜色.

B = Button(frame, image=logo, command=data)
b1 = Button(frame, text = "v", command=lambda:b1.config(bg="gray))
b2 = Button(frame, text = "v", command=lambda:b2.config(bg="gray))
b3 = Button(frame, text = "v", command=lambda:b3.config(bg="gray))
Run Code Online (Sandbox Code Playgroud)

因此,当我单击按钮时,背景颜色变为灰色.但是,我想一次只做一个按钮.因此,当我单击一个按钮时,我想将其他按钮更改为前景.通过使用背景颜色,我想编写按钮B命令功能.

我尝试如下,但它没有按我的意愿工作:

def data():
    if b1.configure(bg="gray):
       data1()
    if b2.configure(bg="gray):
       data2()
    if b3.configure(bg="gray):
       data3()
    else:
        print('no data')

def data1():
    as per my requirement 
def data2():
    as per my requirement 
def data3():
     as per my requirement 
Run Code Online (Sandbox Code Playgroud)

但是,尽管点击按钮,我仍然没有数据.

很高兴听到一些建议.

python tkinter

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

标签 统计

python ×3

pandas ×2

dataframe ×1

excel ×1

tkinter ×1