我是大熊猫的新手,我很难相处。我有两个数据框:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context=".activity.Splash"
tools:showIn="@layout/activity_splash"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardUseCompatPadding="true"
android:elevation="5dp"
android:stateListAnimator="@anim/button_elevation"
android:id="@+id/one"
android:layout_marginLeft="@dimen/activity_horizontal_margin"
>
<RelativeLayout
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="@dimen/activity_horizontal_margin"
android:background="?attr/selectableItemBackground"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="this is just for test"
/>
</RelativeLayout>
</android.support.v7.widget.CardView>
<ImageView
android:layout_marginRight="@dimen/activity_horizontal_margin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/cross"
android:id="@+id/two"
android:layout_centerVertical="true"
android:elevation="10dp"
/>
</RelativeLayout>
</RelativeLayout>
我想做的是: 如果地址&amp; df1中的邮政编码列等于地址&amp; df2的邮政编码列,使用df2中相应的宗地编号值填充df1宗地编号栏中的NaN值。
任何帮助将不胜感激!
答案 0 :(得分:3)
这称为combine_first
。首先在['地址','Zip']上索引数据帧:
Df1.set_index(['Address', 'Zip'], inplace=True)
Df2.set_index(['Address', 'Zip'], inplace=True)
Df1.combine_first(Df2)
如果要将Address和Zip保留为列
,可以reset_index结果数据帧