Python Excel Data Manipulation with Pandas
To read an Excel file and process data, you can use the pandas library in Python. Here is a simple example code to read an Excel file, process the data, and save the processed data to a new Excel file:
import pandas as pd
# 读取Excel文件
df = pd.read_excel('data.xlsx')
# 处理数据
df['new_column'] = df['column1'] + df['column2']
# 保存处理后的数据到新的Excel文件
df.to_excel('processed_data.xlsx', index=False)
In this example, we start by using the pd.read_excel() function to read an Excel file named data.xlsx and store the data in a DataFrame called df. Next, we create a new column called new_column while processing the data, which is the sum of columns column1 and column2. Finally, we use the to_excel() function to save the processed data to a new Excel file named processed_data.xlsx, with the index=False parameter indicating that the row index should not be saved.
By using the pandas library, Python can effortlessly read and manipulate data from Excel files, making data processing easier and more efficient.