虽然您可以使用csv
如果您需要逐行处理 csv 文件,则模块pandas
and matplotlib
模块为数据分析任务提供了更高级别的接口。
data.csv
x,y
1,2
2,4
3,6
4,7
5,11
6,12
7,13
8,20
9,17
10,19
plots.py
import pandas as pd
import matplotlib.pyplot as plt
df = pd.read_csv("data.csv")
df.plot() # plots all columns against index
df.plot(kind='scatter',x='x',y='y') # scatter plot
df.plot(kind='density') # estimate density function
# df.plot(kind='hist') # histogram
output
怎么运行的
df = pd.read_csv("data.csv")
读取 csv() http://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_csv.html将 csv 文件读入熊猫数据框 http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.html
dataframe 绘图方法是 matplotlib 绘图的包装器,并且是记录在这里 http://pandas.pydata.org/pandas-docs/stable/visualization.html
请注意,我们可以通过调整来获得不同类型的图kind=
关键字参数为df.plot()
。直方图可用,在比此处安装的更新版本的 matplotlib 中,kind='hist'