python 连续输出日期_for循环花费太长的时间来产生/输出Python的输出

This question is a continuation of a previous question for loop taking too long to produce output that I asked earlier today. As advised to me in one comment, I used pandas for reading excel files in place of xlrd. Here is the program that I wrote -

import pandas as pd

import numpy as np

no_of_columns = 10000

Book1 = pd.read_excel("D:\Python\Book1.xlsx",header=None,name=range(no_of_columns))

Book2 = pd.read_excel("D:\Python\Book2.xlsx",header=None,name=range(no_of_columns))

Book3 = pd.read_excel("D:\Python\Book3.xlsx",header=None,name=range(no_of_columns))

for i in range(1,11001):

for j in range(0,10000):

if Book1.iloc[i,j] == 100 and Book2.iloc[i,j] == 150 and Book3.iloc[i,j] == 150:

print 1

else:

print 0

But this also didn't solved the problems that I am having. The program is still running (it has been 5 hours) and the text output that I am exporting in my directory is still of size 0 bytes. Again, is there anything wrong with the program? Why am I getting a file whose size has been the same since the beginning of the execution? I have ran such kind of large loops on R but each time I started to export my output in text or in excel format, I get a file in my directory whose size continues to increase as the loop progresses. So why this isn't happening here? What should I do here?

解决方案

IIUC:

Assuming all books are same size

(Book1.eq(100) & Book2.eq(150) & Book3.eq(150)) * 1

Response to comment:

I wrote this for aesthetics as well. To replicate what you've done and get results to a csv, I'd do this:

(Book1.eq(100) & Book2.eq(150) & Book3.eq(150)).stack().mul(1) \

.to_csv('filename.csv', header=False, index=False)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值