1.1. Exercises

Delimiter

Coding questions

Instructions:
Running a coding exercise for the first time could take a bit of time for everything to load. Be patient, it could take a few minutes.

When you see ____ in a coding exercise, replace it with what you assume to be the correct code. Run it and see if you obtain the desired output. Submit your code to validate if you were correct.

Reading in a URL

Let’s try reading in some data from a URL using pd.read_csv().

Tasks:

  • Use pd.read_csv() to read in the data from this url using the name column as the index.
  • Save the resulting dataframe as pokemon_df.
  • Display the first 10 rows of the dataframe.
Hint 1
  • Are you sure you are saving your dataframe as pokemon_df?
  • Are you using pd.read_csv()?
Fully worked solution:


Reading in a Text File

Let’s try reading in a .txt file.

Tasks:

  • Read in the data from a text file name pokemon-text.txt located in the data folder.
  • Save the resulting dataframe as pokemon_df.
  • It’s a good idea to see what the delimiter is.
  • Display the first 10 rows of pokemon_df.
Hint 1
  • Are you sure you are saving your dataframe as the correct object names?
  • Are you using pd.read_csv()?
  • Did you check to see what the delimiter is.
  • Are you including the full path through the data/ folder when calling the file name?
  • Check that your delimiter argument is correct.
Fully worked solution:


Reading in an Excel File

Let’s try reading in an Excel file.

Tasks:

  • Read in the data from the sheet named pokemon from the Excel file pokemon.xlsx located in the data folder.
  • Save the resulting dataframe as pokemon_df.
  • Display the first 10 rows of pokemon_df.
Hint 1
  • Are you sure you are saving your dataframe as the correct object names?
  • Are you using pd.read_excel()?
  • Check that you are using sheet_name="pokemon".
  • Are you including the full path through the data/ folder when calling the file name?
Fully worked solution: