Tidy Data in Python

Hi all,

I could not find any feedback regarding this small exercise so here is my solution.
Please feel free giving constructive criticism :grinning:.

import pandas as pd

country = pd.read_csv(“country.csv”)

# Extract Country abbreviation and Feature from ‘Country_Feature’ using regular expressions
sep = country[“Country_Feature”].str.extract(’(\w{1,3})(\w{3,6})’)

# Name Columns “Country” and “Feature”
sep.columns = [‘Country’, ‘Feature’]

# Merge country and sep
country = pd.concat([country, sep], axis = 1)

# Drop ‘Country_Feature’ column
country = country.drop([‘Country_Feature’], axis = 1)

# Sort Columns to ‘Country’, ‘Feature’, and ‘Observation’
country = country[[‘Country’, ‘Feature’, ‘Observation’]]

# Print country
print(country)

Welcome to the forums!

Is there a link to the lesson? Did you get any errors or did your code run successfully?
Without a (jupyter or colab) notebook, it’s difficult to visualize the results from the code.