
Pandas là công cụ mạnh mẽ để xử lý dữ liệu. Chúng ta sẽ đọc file Excel và vẽ biểu đồ doanh thu.
1. Tạo file sales.xlsx (dùng Excel, lưu thủ công):
Month,Revenue
Jan,5000
Feb,7000
Mar,6000
2. File analyze.py:
import pandas as pd
import matplotlib.pyplot as plt
# Đọc file Excel
df = pd.read_excel('sales.xlsx')
# Tính tổng doanh thu
total_revenue = df['Revenue'].sum()
print(f"Tổng doanh thu: {total_revenue}")
# Vẽ biểu đồ
plt.bar(df['Month'], df['Revenue'], color='blue')
plt.title('Doanh thu theo tháng')
plt.xlabel('Tháng')
plt.ylabel('Doanh thu')
plt.show()