
PYTHON — Loading Dataset in Python
In the software world, the moment you start using someone else’s software, you are living in their world, under their philosophy. — Richard Stallman
Insights in this article were refined using prompt engineering methods.

PYTHON — Python Markup with reStructuredText
# Loading Dataset in Python
In this tutorial, you will learn how to load a dataset in Python using the requests package and how to import the dataset into a Pandas DataFrame. Additionally, you will explore some common operations on the DataFrame such as displaying the first and last few rows, understanding shape, and working with column formatting.
Loading Dataset using requests
To begin, you can use the requests package to download a CSV file containing basketball data from the website FiveThirtyEight. If you have Anaconda installed, requests is included in the default environment. If not, you can install it using pip.
import requests
download_url = 'https://raw.githubusercontent.com/fivethirtyeight/data/master/nba-elo/nbaallelo.csv'
response = requests.get(download_url)
if response.status_code == 200:
with open('nba_all_elo.csv', 'wb') as f:
f.write(response.content)
# Now the contents of the file are stored locallyImporting the Dataset into Pandas DataFrame
After downloading the CSV file, you can import it into a Pandas DataFrame. To do this, import the pandas package and use the read_csv() function.
import pandas as pd
nba = pd.read_csv('nba_all_elo.csv')
# Check the type of nba
print(type(nba))
# Get the length of the DataFrame
print(len(nba))
# Get the shape of the DataFrame
print(nba.shape)
# Display the first five rows of the DataFrame
print(nba.head())
# Display the last five rows of the DataFrame
print(nba.tail())Adjusting Display Settings
By default, Pandas will display only a limited number of columns and rows. To adjust the display, you can set the maximum number of columns and the number of decimal places for numeric columns.
# Set maximum number of columns to be displayed
pd.set_option('display.max_columns', None)
# Set the number of decimal places to two
pd.set_option('display.float_format', '{:.2f}'.format)Conclusion
In this tutorial, you learned how to load a dataset using the requests package and import it into a Pandas DataFrame. Additionally, you learned about adjusting display settings for the DataFrame. These are the foundational steps that will enable you to work with datasets and perform data analysis using Python and Pandas.







