Sarah111-AHM / Semsmah

2 stars 0 forks source link

5 #32

Closed Sarah111-AHM closed 1 year ago

Sarah111-AHM commented 1 year ago

الكود النهائي سيكون كالتالي:

import pandas as pd

data = {'col1': [1, 2, 3, 4, 7, 11, 22, 3, 2, 3, 9], 'col2': [4, 5, 6, 9, 5, 0, 4, 6, 7, 8, 0], 'col3': [7, 5, 8, 12, 1, 11, 5, 8, 22, 6, 5]}
df = pd.DataFrame(data)

series = df['col1']
most_frequent_value = series.value_counts().index[0]
series = series.where(series == most_frequent_value, other='Other')

print(series)

النتيجة ستكون:

0         Other
1              2
2              3
3         Other
4         Other
5         Other
6         Other
7              3
8              2
9              3
10        Other
Name: col1, dtype: object