train_df = pd.read_csv('./data/train.csv', index_col = 0) test_df = pd.read_csv('./data/test.csv', index_col = 0) print("Number of rows: ", train_df.shape[0]) print("Number of columns: ", train_df.shape[1]) display(train_df) train_df.info() print("Number of rows: ", test_df.shape[0]) print("Number of columns: ", test_df.shape[1]) display(test_df) test_df.info() train_df.describe() # Check for NaN values and the number of unique values print("Are there any NaN values: ", train_df.isnull().values.any()) print(train_df.nunique()) # Count NaN values in each column nan_counts = train_df.isna().sum() # Print the counts print(nan_counts)
时间: 2024-04-02 22:34:40 浏览: 196
Kaggle_Titanic_train.csv泰坦尼克数据集.zip
5星 · 资源好评率100%
这段代码是用来读取两个csv文件,并对它们进行一些数据分析的。具体来说,它首先读取了一个名为train.csv的文件和一个名为test.csv的文件,并打印了它们的行数和列数。然后,它显示了train_df和test_df的内容和信息,包括每个列的数据类型和非空值的数量。接下来,它使用describe()函数对train_df进行描述统计,包括平均值、标准差、最小值、最大值等。最后,它检查train_df中是否有NaN值,并计算每列中的NaN值的数量,并打印出来。
阅读全文