How to import CSV data and plot it using Python?

You can import CSV data and plot it using the pandas and matplotlib libraries. Here is a simple example:

import pandas as pd
import matplotlib.pyplot as plt

# 导入csv数据
data = pd.read_csv('data.csv')

# 绘制折线图
plt.plot(data['x'], data['y'])

# 添加标题和标签
plt.title('CSV数据折线图')
plt.xlabel('x')
plt.ylabel('y')

# 显示图形
plt.show()

Please note that this example assumes you have a file called “data.csv” which contains two columns of data, “x” and “y”. You can modify the code accordingly to fit your own data.

Leave a Reply 0

Your email address will not be published. Required fields are marked *


广告
Closing in 10 seconds
bannerAds