在读完整个Excel文件之前,大pandas会早退

我正在尝试将Python excel文件读入Pandas,访问每行的特定列,然后将地址编码为坐标。 然后把它们写入一个csv

地理编码部分工作良好,据我所知,我的循环开始好的地方,它可以读取地址。 然而,它只是停止22行。 我不知道为什么,我一直在使用pandas这个相同的Excel文件的东西,它没有问题。 只是做这个,不是那么多。 它有27K行。 打印data.__len__()给我27395 。 任何帮助?

 ##### READ IN DATA file = r'rollingsales_manhattan.xls' # Read in the data from the Excel data = pd.read_excel(file) # g = geocoder.osm(str(data['ADDRESS'].iloc[0]) + " New York City, NY " + str(data['ZIP CODE'].iloc[0])) with open("geotagged_manhattan.csv", 'wb') as result_file: wr = csv.writer(result_file) for index,d in enumerate(data): print(str(data['ADDRESS'].iloc[index]) + " New York City, NY " + str(data['ZIP CODE'].iloc[index])) 

然后我的输出…

 345 WEST 14TH STREET New York City, NY 10014 345 WEST 14TH STREET New York City, NY 10014 345 WEST 14TH STREET New York City, NY 10014 345 WEST 14TH STREET New York City, NY 10014 345 WEST 14TH STREET New York City, NY 10014 345 WEST 14TH STREET New York City, NY 10014 345 WEST 14TH STREET New York City, NY 10014 345 WEST 14TH STREET New York City, NY 10014 345 WEST 14TH STREET New York City, NY 10014 345 WEST 14TH STREET New York City, NY 10014 345 WEST 14TH STREET New York City, NY 10014 345 WEST 14TH STREET New York City, NY 10014 345 WEST 14TH STREET New York City, NY 10014 345 WEST 14TH STREET New York City, NY 10014 345 WEST 14TH STREET New York City, NY 10014 345 WEST 14TH STREET New York City, NY 10014 345 WEST 14TH STREET New York City, NY 10014 229 EAST 2ND STREET New York City, NY 10009 243 EAST 7TH STREET New York City, NY 10009 238 EAST 4TH STREET New York City, NY 10009 303 EAST 4TH STREET New York City, NY 10009 Process finished with exit code 0 

您需要使用iteritems()方法遍历Pandas系列。 要迭代它们,使用map()像这样…

 with open("geotagged_manhattan.csv", 'wb') as result_file: wr = csv.writer(result_file) for a, z in map(None, data['ADDRESS'].iteritems(), data['ZIP CODE'].iteritems()): print(str(a[1]) + " New York City, NY " + str(z[1]))