Python Pandas-查找具有最相似元素的行

Python Pandas-查找具有最相似元素的行,python,pandas,dataframe,Python,Pandas,Dataframe,我有一个混合数据类型、字符串、浮点和整数的数据帧。我想写一个函数,它接受一个数据帧、索引和一个整数k,它将返回一个数据帧,该数据帧包含df中的k行,这些行与我指定的索引行具有最多的公共条目(即完全匹配的条目) Lottery Type Do you ever smoke cigarettes? Do you ever drink alcohol? Do you ever gamble? Have you ever been skydiving? Do you ever d

我有一个混合数据类型、字符串、浮点和整数的数据帧。我想写一个函数,它接受一个数据帧、索引和一个整数k,它将返回一个数据帧,该数据帧包含df中的k行,这些行与我指定的索引行具有最多的公共条目(即完全匹配的条目)

    Lottery Type    Do you ever smoke cigarettes?   Do you ever drink alcohol?  Do you ever gamble? Have you ever been skydiving?   Do you ever drive above the speed limit?    Have you ever cheated on your significant other?    Do you eat steak?   How do you like your steak prepared?    Gender  Age Household Income    Education   Location (Census Region)
RespondentID                                                        
3237565956  Lottery B   NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
3234982343  Lottery A   No  Yes No  No  No  No  Yes Medium rare Male    60+  50,000− 99,999 Some college or Associate degree    East North Central
3234973379  Lottery A   No  Yes Yes No  Yes Yes Yes Rare    Male    60+ $150,000+   Graduate degree South Atlantic

这是df的一个示例摘要。我看了类似的问题,但它们都有整数值,所以使用了欧几里得距离。我该怎么做?

基于您的数据帧,此函数的输出是什么?您自己的尝试在哪里?