对于data.columns = ['city1', 'country1', 'city2', 'country2']的dataframe,这段loop代码for i, row in data.iterrows(): # get city1 city1 = ??? # get country1 country1 = ??? # get city2 city2 = ??? # get country2 country2 = ???
在循环中,你可以使用 `loc` 方法来获取每行的对应列值。假设你的DataFrame命名为`data`,这个循环可以像下面这样写:
```python
for i, row in data.iterrows():
# get city1
city1 = row['city1']
# get country1
country1 = row['country1']
# get city2
city2 = row['city2']
# get country2
country2 = row['country2']
# 现在你可以使用这些变量进行后续的处理
# 例如,打印这些值
print(f"City1: {city1}, Country1: {country1}, City2: {city2}, Country2: {country2}")
```
这样,`row['city1']` 就获取了每一行中列名为 'city1' 的值,以此类推。你可以根据实际需要,在循环中使用这些变量进行后续的操作。