We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1
4/23/24, 10:59 AM about:blank
Data Analysis with Python
Cheat Sheet: Importing Data Sets Package/Method Description Code Example 1. 1
1. df = pd.read_csv(<CSV_path>, header = None)
# load without header df = pd.read_csv(<CSV_path>, header = 0) # load using first row as header Read the CSV file containing a Read CSV data set data set to a pandas data frame Copied! Note: The labs in this course run in JupyterLite environment. In JupyterLite environment, you'll need to download the required file to the local environment and then use the local path to the file as the CSV_path. However, in case you are using JupyterLabs, or any other Python compiler on your local machine, you can use the URL of the required file directly as the CSV_path. 1. 1 Print the first few entries Print first few 1. df.head(n) #n=number of entries; default 5 (default 5) of the pandas data entries frame Copied! 1. 1 Print the last few entries Print last few 1. df.tail(n) #n=number of entries; default 5 (default 5) of the pandas data entries frame Copied! 1. 1 Assign header Assign appropriate header 1. df.columns = headers names names to the data frame Copied! 1. 1 Replace "?" with Replace the entries "?" with 1. df = df.replace("?", np.nan) NaN NaN entry from Numpy library Copied! 1. 1 Retrieve the data types of the 1. df.dtypes Retrieve data types data frame columns Copied! Retrieve the statistical description of the data set. 1. 1 Retrieve statistical Defaults use is for only 1. df.describe() #default use df.describe(include="all") description numerical data types. Use include="all" to create Copied! summary for all variables 1. 1 Retrieve the summary of the Retrieve data set 1. df.info() data set being used, from the summary data frame Copied! 1. 1 Save the processed data frame Save data frame to 1. df.to_csv(<output CSV path>) to a CSV file with a specified CSV path Copied!