-
wbdata 5
-
Lecture1.1
-
Lecture1.2
-
Lecture1.3
-
Lecture1.4
-
Lecture1.5
-
-
Hexbin Plots 7
-
Lecture2.1
-
Lecture2.2
-
Lecture2.3
-
Lecture2.4
-
Lecture2.5
-
Lecture2.6
-
Lecture2.7
-
-
Heatmap 5
-
Lecture3.1
-
Lecture3.2
-
Lecture3.3
-
Lecture3.4
-
Lecture3.5
-
-
Boxplot 2
-
Lecture4.1
-
Lecture4.2
-
-
Violin Plot 5
-
Lecture5.1
-
Lecture5.2
-
Lecture5.3
-
Lecture5.4
-
Lecture5.5
-
-
Time Series 2
-
Lecture6.1
-
Lecture6.2
-
-
Pairplot 2
-
Lecture7.1
-
Lecture7.2
-
-
Kernel Density Estimation 3
-
Lecture8.1
-
Lecture8.2
-
Lecture8.3
-
Swarmplot Part 2
Solution
from sklearn import preprocessing
df = wbdata.get_dataframe(indicators, country=countries, data_date=dates)
df.dropna(inplace=True)
df.reset_index(inplace=True)
x = df[['GDP', 'Inflation', 'Oil Rents', 'Pollution']].values
min_max_scaler = preprocessing.MinMaxScaler()
x_scaled = min_max_scaler.fit_transform(x)
df[['GDP', 'Inflation', 'Oil Rents', 'Pollution']] = x_scaled
del(df["date"])
We use the line x = df[[‘GDP’, ‘Inflation’, ‘Oil Rents’, ‘Pollution’]].values to set x equal to the values of variable columns, min_max_scaler = preprocessing.MinMaxScaler() creates an object for setting our scaler, x_scaled = min_max_scaler.fit_transform(x) scales x values and finally df[[‘GDP’, ‘Inflation’, ‘Oil Rents’, ‘Pollution’]] = x_scaled reassigns our values to the columns.
Melt it down again, and plot!
df = pd.melt(df, "country", var_name="indicator")
sns.swarmplot(x="indicator", y="value", hue="country", data=df)
plt.show()
Source Code
Prev
Swarmplot
Next
Introduction