我正在尝试将非常大的数据帧df1重塑为df2,但由于其大小,我遇到了内存错误:
State
这是我到目前为止尝试过的:
from tkinter import *
from tkinter import ttk
thething = ['O','B','A','F','G','K','M','L']
BACKGROUND = "#2c2d31"
def scaleFunc(val):
scaleVal = float(w.get())
if int(scaleVal) != scaleVal:
w.set(round(float(val)))
print (thething[(int(w.get()))])
master = Tk()
master["bg"] = BACKGROUND
master.geometry("800x550")
s = ttk.Style()
s.configure("Horizontal.TScale", background=BACKGROUND)
w = ttk.Scale(master, to=7, command=scaleFunc, length=None, style="Horizontal.TScale")
w.place( x = 150, y = 30, width = 500)
mainloop()
,但仅适用于较小的示例。有没有办法做到这一点呢?
答案 0 :(得分:2)
不确定内存错误是否会消失,但是我会用这个:
df2 = df1.stack().reset_index().rename(columns={'level_0': 'Ticker', 'level_1': 'Date', 0: 'flag'})
df2 = df2[df2['flag'] == 1]
df2 = df2[['Ticker', 'Date']].set_index('Ticker')