1. Reading or Loading Data

In this Document , You will cover how to load different types of data in pandas.

Before Going ahead Download all these Files and Save in your project.

How to read Excel File (Sales.xlsx)

To read an Excel file like "Sales.xlsx" in Python, you can use the pandas library along with openpyxl for modern Excel files (.xlsx) or xlrd for older Excel files (.xls). Below is an example:

import pandas as pd

# Load the Excel file
df = pd.read_excel('Sales.xlsx')

# Display the DataFrame
print(df)

Ensure you have installed the necessary libraries before running this script in the terminal:

pip install pandas openpyxl

How to read CSV Files (Sales.csv)

To read a CSV file like "Sales.csv" in Python, you can use the pandas library. Below is an example:

import pandas as pd

# Load the CSV file
df = pd.read_csv('Sales.csv')

# Display the DataFrame
print(df)

Ensure that pandas is installed, as shown previously. With this approach, you'll be able to load and analyze your CSV data efficiently.

How to read json files (Employee_sales_data.json)

To read a JSON file like "Employee_sales_data.json" in Python, you can also use the pandas library. Here's how you can do it:

import pandas as pd

# Load the JSON file
df = pd.read_json('Employee_sales_data.json')

# Display the DataFrame
print(df)

Ensure pandas is installed to access and manipulate your JSON data effectively. This approach is useful for processing JSON files with ease.

How to read Multiple sheets from Sales and customer.xlsx

To read multiple sheets from an Excel file like "Sales and customer.xlsx" into separate DataFrames, you can use the pandas library's read_excel function with the sheet_name parameter. Here's how you can do it:

import pandas as pd



# Read the 'Sales' sheet into a DataFrame
sales_df = pd.read_excel('Sales and customer.xlsx', sheet_name='Sheet1')

# Read the 'Customer' sheet into another DataFrame
customer_df = pd.read_excel('Sales and customer.xlsx', sheet_name='Sheet2')

# Display the DataFrames
print(sales_df)
print(customer_df)

This method allows you to read specific sheets by specifying their names and loading them into different DataFrames for further processing.

Last updated