{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import pandas as pd\nimport matplotlib.pyplot as plt\nimport seaborn as sns\n\n# Load the CSV file\ndf = pd.read_csv('/kaggle/input/goodreads-books-reviews-290312/goodreads_train.csv')\n\n# Print the first few rows of the dataset\nprint(df.head())\n\n# Get summary statistics of the numerical columns\nprint(df.describe())\n\n# Generate a histogram of the ratings\nplt.hist(df['rating'])\nplt.xlabel('Rating')\nplt.ylabel('Frequency')\nplt.title('Distribution of Ratings')\nplt.show()\n\n\n# Generate a scatterplot of the length of the reviews vs. the rating\nsns.scatterplot(x=df['n_comments'], y=df['rating'])\nplt.xlabel('Number of comments')\nplt.ylabel('Rating')\nplt.title('Rating vs. Review Length')\nplt.show()","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-03-19T03:19:21.114705Z","iopub.execute_input":"2023-03-19T03:19:21.115463Z","iopub.status.idle":"2023-03-19T03:19:33.910852Z","shell.execute_reply.started":"2023-03-19T03:19:21.115424Z","shell.execute_reply":"2023-03-19T03:19:33.909790Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(list(df.columns))","metadata":{"execution":{"iopub.status.busy":"2023-03-19T03:19:33.912409Z","iopub.execute_input":"2023-03-19T03:19:33.912709Z","iopub.status.idle":"2023-03-19T03:19:33.918300Z","shell.execute_reply.started":"2023-03-19T03:19:33.912683Z","shell.execute_reply":"2023-03-19T03:19:33.917000Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pandas as pd\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport seaborn as sns\n\n# Load data from CSV file into a pandas DataFrame\ndf = pd.read_csv('/kaggle/input/goodreads-books-reviews-290312/goodreads_train.csv')\n\n# Set style and color palette\nsns.set_style('white')\nsns.set_palette('Set2')\n\n# Check for missing values\nmissing_values = df.isnull().sum()\nif missing_values.sum() > 0:\n    missing_perc = 100 * missing_values / len(df)\n    print(f\"Missing values:\\n{pd.concat([missing_values, missing_perc], axis=1, keys=['Count', 'Percentage'])}\\n\")\nelse:\n    print(\"No missing values.\\n\")\n\n# Summary statistics\nprint(\"Summary statistics:\\n\", df.describe(), \"\\n\")\n\n# Distribution of target variable\nplt.figure(figsize=(6,4))\nplt.hist(df['rating'], bins=10, edgecolor='black')\nplt.xlabel('Rating')\nplt.ylabel('Count')\nplt.title('Distribution of Ratings')\nplt.tight_layout()\nplt.show()\n\n# Correlation matrix\nplt.figure(figsize=(10,8))\nsns.heatmap(df.corr(), cmap='coolwarm', annot=True, fmt='.2f', annot_kws={'fontsize':12})\nplt.title('Correlation Matrix')\nplt.tight_layout()\nplt.show()\n\n# Pairwise scatterplots\nsns.pairplot(df, diag_kind='kde', height=2.5)\nplt.tight_layout()\nplt.show()\n\n# Distribution of numerical variables\nnumerical_cols = ['n_votes', 'n_comments']\nfor col in numerical_cols:\n    plt.figure(figsize=(6,4))\n    plt.hist(df[col], bins=20, edgecolor='black')\n    plt.xlabel(col)\n    plt.ylabel('Count')\n    plt.title(f'Distribution of {col}')\n    plt.tight_layout()\n    plt.show()\n\n# Distribution of categorical variables\ncategorical_cols = ['user_id', 'book_id']\nfor col in categorical_cols:\n    value_counts = df[col].value_counts()\n    plt.figure(figsize=(6,4))\n    plt.bar(range(len(value_counts)), value_counts, edgecolor='black')\n    plt.xticks(range(len(value_counts)), value_counts.index, rotation=90, fontsize=10)\n    plt.xlabel(col, fontsize=12)\n    plt.ylabel('Count', fontsize=12)\n    plt.title(f'Distribution of {col}', fontsize=14)\n    plt.tight_layout()\n    plt.show()\n\n# Top rated books\ntop_rated_books = df.groupby('book_id')['rating'].mean().sort_values(ascending=False)[:10]\nplt.figure(figsize=(8,6))\nplt.bar(range(len(top_rated_books)), top_rated_books.values, edgecolor='black')\nplt.xticks(range(len(top_rated_books)), top_rated_books.index, rotation=90, fontsize=12)\nplt.xlabel('Book ID', fontsize=14)\nplt.ylabel('Average Rating', fontsize=14)\nplt.title('Top Rated Books', fontsize=16)\nplt.tight_layout()\nplt.show()\n\n# Top rated users\ntop_rated_users = df.groupby('user_id')['rating'].mean().sort_values(ascending=False)[:10]\nplt.figure(figsize=(8,6))\nplt.bar(range(len(top_rated_users)), top_rated_users.values, edgecolor='black')\nplt.xticks(range(len(top_rated_users)), top_rated_users.index, rotation=90, fontsize=12)\nplt.xlabel('User ID', fontsize=14)\nplt.ylabel('Average Rating', fontsize=14)\nplt.title('Top Rated Users', fontsize=14)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-03-19T03:19:33.919597Z","iopub.execute_input":"2023-03-19T03:19:33.919950Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}