practice PandasCSV
中文版:Pandas CSV 练习
Start from reading CSV
-
What is a .csv file? Try opening nba.csv (Ensure the file is saved in your working directory) using Excel and observe its structure.(no code)
-
Import the pandas library in Python and use pd as an alias.
# hint: how to import numpy: import numpy as np- Read the nba.csv file using pandas and store it in a DataFrame named df
# hint: pd.read_csv(file_name_string)
df =- Print the shape of df (number of rows and columns) and list all column names. Answer the questions: how many persons are listed in the df, and how many types of information for each person in the df, and what are they?
# hint: df.shape df.columns.tolist()
print("sizes of dimensions(rows, cols):", ?)
print("types of information:", ?)- Print the data types of each column (e.g., int, float, string), and check the memory usage of df.
# hint: df.dtypes
print("data type for cols:\n", ?)
print("memory usage:")
df.info(memory_usage="deep")- Print all information of the first person (= the first row).
# hint: df.iloc[index]
print("information of first person:\n", df.iloc[?])- Print the last five rows and compare with the original nba.csv file to verify correct data loading.
# hint: df.iloc[:]
print("the last five rows:\n", df.iloc[-5:])