pandas——将sql查询结果,分几部分存入excel

    f = pd.read_sql(con=conn, sql=sql)
    df1 = f.iloc[:1000000, :]
    df2 = f.iloc[1000000:2000000, :]
    df3 = f.iloc[2000000:3000000, :]
    df4 = f.iloc[3000000:4000000, :]
    df5 = f.iloc[4000000:, :]
    with pd.ExcelWriter('forth.xlsx') as writer:
        df1.to_excel(writer, sheet_name='4_1')
        df2.to_excel(writer, sheet_name='4_2')
        df3.to_excel(writer, sheet_name='4_3')
        df4.to_excel(writer, sheet_name='4_4')
        df5.to_excel(writer, sheet_name='4_5')

loc : 根据行列名称筛选。
iloc : 根据行列索引筛选。

上一篇:pandas中有关DataFrame的常用用法


下一篇:Unit2 Preparing for a negotiation