![](/img/trans.png)
[英]How do I update some values of my target column in a dataframe by matching its multiple columns with one column in another dataframe in python?
[英]How do I combine the float values of two columns and put it in an another column of my dataframe?
我正在使用數據集- Meteorite Landings,可以在這里找到- https://www.kaggle.com/nasa/meteorite-landings#meteorite-landings.csv
數據集有很多缺失值,在填充列reclat和reclong的值后,我嘗試將它們以字符串的形式組合並放入GeoLocation列。
reclat col: reclong col:
0 50.77500 0 6.08333
1 56.18333 1 10.23333
2 54.21667 2 -113.00000
3 16.88333 3 -99.90000
4 -33.16667 4 -64.95000
問題是組合值沒有以我想要的所需坐標格式顯示。
我正在嘗試結合 relat 和 reclong 的值,最好是坐標格式。
以字符串形式組合這兩個值並將其插入到 GeoLocation 列中
data['GeoLocation']=str(data['reclat'])+str(data['reclong'])
我希望 GeoLocation 列將 relat 和 reclong 的值附加在一起,但它的格式不同,如下所示。
0 0 50.77500\n1 56.18333\n2 ...
1 0 50.77500\n1 56.18333\n2 ...
2 0 50.77500\n1 56.18333\n2 ...
3 0 50.77500\n1 56.18333\n2 ...
4 0 50.77500\n1 56.18333\n2 ...
Name: GeoLocation, dtype:object
首先,將所有浮點值類型轉換為字符串:
data['reclat'] = data['reclat'].astype(str)
data['reclong'] = data['reclong'].astype(str)
然后,只需將兩列的值相加即可生成 output 字符串。 它將被附加。
data['GeoLocation'] = data['reclat'] + data['reclong']
我希望這是你想要的。 如果沒有相應地讓我知道。
data['GeoLocation'] = data['reclat'].astype(str) + ' ' + data['reclong'].astype(str)
請嘗試上面的代碼。
鍵入強制轉換列,您可以連接成單個列。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.