Write some sample code for Jupyter Notebook
- User
Write some sample code for Jupyter Notebook
- Assistant
Sure! Here's a simple code snippet to get you started with Jupyter Notebook:
# Importing necessary libraries import pandas as pd # Reading a CSV file data = pd.read_csv('data.csv') # Exploring the data print('First 5 rows of the data:') print(data.head()) print('Data summary statistics:') print(data.describe())This code imports the
pandaslibrary, reads a CSV file calleddata.csv, and then displays the first 5 rows of the data as well as the summary statistics. You can run this code cell in Jupyter Notebook by pressingShift + Enteror clicking on the "Run" button. - User
Is this all in one cells or different cells?
- Assistant
This sample code can be written in multiple cells within Jupyter Notebook. Here's how it can be divided into separate cells:
Cell 1:
# Importing necessary libraries import pandas as pdCell 2:
# Reading a CSV file data = pd.read_csv('data.csv')Cell 3:
# Exploring the data print('First 5 rows of the data:') print(data.head())Cell 4:
print('Data summary statistics:') print(data.describe())In Jupyter Notebook, you can run each cell independently by selecting it and pressing
Shift + Enter. This allows you to execute and test different parts of your code separately, which can be helpful for debugging or analyzing data step by step.