能否提供一份Python中用于数据分析和可视化的源代码示例?
时间: 2024-10-09 15:12:44 浏览: 82
当然可以。Python中有许多库非常适合数据分析和可视化,比如Pandas用于数据处理,Matplotlib和Seaborn用于数据可视化。以下是一个简单的例子,演示了如何使用这些库读取CSV文件、处理数据并生成图表:
```python
# 导入所需的库
import pandas as pd
import matplotlib.pyplot as plt
# 读取CSV文件
data = pd.read_csv('example_data.csv') # 假设你有一个名为example_data.csv的文件
# 数据清洗和预处理(如查看前几行)
print(data.head())
# 数据分析示例:计算平均值
mean_values = data.mean()
print(mean_values)
# 数据可视化 - 绘制柱状图
plt.figure(figsize=(10,6))
plt.bar(data['Category'], data['Value'])
plt.xlabel('类别')
plt.ylabel('值')
plt.title('各分类平均值')
plt.show()
阅读全文
相关推荐

















