将切片的python数据帧分配到列表中的变量中

时间:2017-08-08 23:27:41

标签: python pandas dataframe

我有两个列表

procedure DoRTF(RTF: TRichedit);
var
    r: TRect;
    richedit_outputarea: TRect;
    printresX, printresY: Real;
    fmtRange: TFormatRange;
    Ratio: Real;
    ScaleFactor: Real;
begin
    ScaleFactor:= 1;

    Ratio:=GetDeviceCaps(printer.canvas.handle, LOGPIXELSX)/GetDeviceCaps(MainForm.canvas.handle, LOGPIXELSX);
    //"r" is the position of the richedit on the printer page       
    r := Rect(badgerect.left+round((RTF.Left-WordsBottom.Left)*Ratio),
            badgerect.Top+round((RTF.Top-WordsTop.Top)*Ratio),
            badgerect.left+round((RTF.Left-WordsBottom.Left)*Ratio +RTF.width*Ratio),
            badgerect.Top+round((RTF.Top-WordsTop.Top)*Ratio+RTF.Height*Ratio)      );

    SetMapMode( printer.canvas.handle, MM_ANISOTROPIC );
    SetWindowExtEx(printer.canvas.handle,
            GetDeviceCaps(printer.canvas.handle, LOGPIXELSX),
            GetDeviceCaps(printer.canvas.handle, LOGPIXELSY),
            nil);
    SetViewportExtEx(printer.canvas.handle,
            Round(GetDeviceCaps(printer.canvas.handle, LOGPIXELSX)*ScaleFactor ),
            Round(GetDeviceCaps(printer.canvas.handle, LOGPIXELSY)*ScaleFactor ),
            nil);

    with Printer.Canvas do
    begin
        printresX := GetDeviceCaps( handle, LOGPIXELSX) ;
        printresY := GetDeviceCaps( handle, LOGPIXELSY) ;

        richedit_outputarea := Rect(
                round(r.left * 1440 / printresX),
                round(r.top * 1440 / printresY),
                round(r.right * 1440 / printresX),
                round(r.bottom* 1440 / printresY) );

        fmtRange.hDC := Handle;
        fmtRange.hdcTarget := Handle;
        fmtRange.rc := richedit_outputarea;
        fmtRange.rcPage:= Rect( 0, 0, round(Printer.PageWidth * 1440 / printresX) , round(Printer.PageHeight * 1440 / printresY) );
        fmtRange.chrg.cpMin := 0;
        fmtRange.chrg.cpMax := RTF.GetTextLen-1;

        // format text
        RTF.Perform(EM_FORMATRANGE, 1, Longint(@fmtRange));

        // Free cached information
        RTF.Perform(EM_FORMATRANGE, 0, 0);
    end
end;

在我的数据库中,有很多数据对应于这三个类别。这是进行大熊猫操作的机械方式,我希望最终缩短它。

make CONFIG=basicprof

我尝试使用for循环

来缩短它
List_1 =[“Category_1”,”Category_2”,”Category_3”]
List_2 =[x,y,z]

我得到的错误是:

x = database1.loc[database1[‘Categories’] == ‘Catergory_1’]
y = database1.loc[database1[‘Categories’] == ‘Catergory_2’]
Z = database1.loc[database1[‘Categories’] == ‘Catergory_3’]

如何将其转换为for循环?

1 个答案:

答案 0 :(得分:0)

你的变量x,y,z没有定义,你得到错误。

您可以设置一个空的List_2并在其中存储操作结果:

List_1 =['Category_1','Category_2','Category_3']
List_2 = list()

for i in List_1:
   List_2.append(database1.loc[database1['Categories'] == i])

print (List_2)

如果您更喜欢变量x,y,z,那么在定义列表之前在程序的开头初始化它们:

x=y=z=None
List_1 =['Category_1','Category_2','Category_3']
List_2 = [x,y,z]