Q:

Write a Pandas program to replace missing white spaces in a given string with the least frequent character

0

Write a Pandas program to replace missing white spaces in a given string with the least frequent character

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

import pandas as pd
str1 = 'abc def abcdef icd'
print("Original series:")
print(str1)
ser = pd.Series(list(str1))
element_freq = ser.value_counts()
print(element_freq)
current_freq = element_freq.dropna().index[-1]
result = "".join(ser.replace(' ', current_freq))
print(result)

Sample Output:

Original series:
abc def abcdef icd
c    3
     3
d    3
f    2
e    2
a    2
b    2
i    1
dtype: int64
abcidefiabcdefiicd

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now