我有一个pandas数据框,其中有Longitude
和Latitude
列。我想从他们那里得到X
和Y
。在utm
中有一个名为from_latlon
的函数来执行此操作。它接收Latitude
和Longitude
,并给出[X,Y]
。我做的是:
def get_X(row):
return utm.from_latlon(row['Latitude'], row['Longitude'])[0]
def get_Y(row):
return utm.from_latlon(row['Latitude'], row['Longitude'])[1]
df['X'] = df.apply(get_X, axis=1)
df['Y'] = df.apply(get_Y, axis=1)
我想定义一个函数get_XY
,并只应用from_latlon
一次以节省时间。我看了一下here、here和here,但是我找不到一种方法来用一个apply
函数生成两列。谢谢。
我从一个类似的线程中合并了几个答案,现在有一个通用的多列输入、多列输出模板,我在Jupyter/pandas中使用:
您可以从函数返回列表:
也可以返回序列。这允许您指定返回值的列名:
相关问题 更多 >
编程相关推荐