如何使用pandas dataframe优化以下代码以查找重复记录县
String shareBody = "content";
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody);
startActivity(Intent.createChooser(sharingIntent, "title"));
名称 1.Rahul 2.Ravi 3.Rahul 4.Raja 5.Ram 6.Sam 7.Teju 8.Guru 9.Rajith 10.Yaj
答案 0 :(得分:0)
有一个查找重复项的功能:DataFrame.duplicated('column_name')
代码:
import pandas as pd
a = {'name': 'John'}
b = {'name': 'Terry'}
c = {'name': 'John'}
df = pd.DataFrame([a, b, c])
print(df)
print('\n')
df['duplicated'] = df.duplicated('name')
print('All duplicates: ')
print(df)
print('\n')
print('Count: ')
print(df['duplicated'].value_counts()) # Counts the number of False (not duplicated) and True (duplicated)
输出:
name
0 John
1 Terry
2 John
All duplicates:
name duplicated
0 John False
1 Terry False
2 John True
Count:
False 2
True 1
Name: duplicated, dtype: int64