擅长:python、mysql、java
<p>我也遇到了同样的问题,正如@oliversm建议的那样,我创建了一个列表,然后将其添加到原始数据集中。
代码如下所示:</p>
<p>。。。。在</p>
<pre><code>results_list=[]
for i, IP in enumerate(df_IP["IP"]):
try :
response = reader.city(IP)
results_list.append( response.city.name,response.location.latitude,response.location.longitude,response.subdivisions.most_specific.iso_code)
except Exception as e:
print ("error with line {}, IP {}: {}").format(i,df_IP["IP"][i],e )
results_array=np.asarray(results_list) #list to array to add to the dataframe as a new column
results['results_column']=pd.Series(results_array,index=results.index)
</code></pre>