column.
import seaborn from matplotlib import pyplot df = seaborn.load_dataset("titanic") most_frequent_value = df["embark_town"].mode() print("Mode: ", most_frequent_value) series1 = df.embark_town.value_counts() pyplot.bar(series1.index, series1.values) pyplot.xlabel("Embark Town") pyplot.ylabel("Number of Passengers") pyplot.savefig("sklearn-titanic-bar-chart.png") pyplot.close()
The value_counts() function here returns a Series. The index of the series are the unique embark towns. And the values of the series are the number of passengers from each of those embark towns. The output of the program shows Southampton is the most frequent value in the column.
Mode: 0 Southampton Name: embark_town, dtype: object
And the corresponding bar chart looks like the following:
So, now we can go ahead and fill all the missing values of the embark town column with “Southampton.” …






0 Comments