使用pandas.DataFrame的plot方法绘制图像会按照数据的每一列绘制一条曲线,默认按照列columns的名称在适当的位置展示图例,比matplotlib绘制节省时间,且DataFrame格式的数据更规范,方便向量化及计算。 DataFrame.plot( )函数: DataFrame.plot(x=None, y=None, kind='line', ax=None, subplots=False, sharex=None, share...
第三个参数 columns= 为列的名字(为list形式) dates = pd.date_range('20200627',periods=6) df = pd.DataFrame(np.random.randn(6,4),index=dates,columns=['a','b','c','d']) print(df) 1. 2. 3. np.random.randn(6,4)函数表示生成正态分布的随机数矩阵。 index表示给每一行命名,columns表...
#上面的操作结果是一个DataFrame,但也是一个长长的“窄表” ''' #做成一个行比较少列比较多的“宽表”,可以将index参数中的列放到columns参数中 #说明:pivot_table函数的fill_value=0会将空值处理为0。 print(pandas.pivot_table(df1, index='销售区域', columns='月份', values='销售额', aggfunc='sum'...
DataFrame.plot方法的参数 DataFrame除了Series中的参数外,还有一些独有的选项。 subplots:将各个DataFrame列绘制到单独的subplot中 sharex,sharey:共享x,y轴 figsize:控制图像大小 title:图像标题 legend:添加图例,默认显示 sort_columns:以字母顺序绘制各列,默认使用当前顺序 柱状图 在生成线型图的代码中加上kind=‘ba...
df.plot(y='水位')plt.show()3 用两幅上下子图的形式来分别绘制 df.plot(subplots=True,figsize=(8,6))plt.legend(loc='best')4 这里如果对流量和水位按照站点的类别进行分类显示,统计站点A和站点B他的水位流量情况,这里就体现了DataFrame的优势了:df_piv1 = pd.pivot_table(df,index=df.index,column...
layout : tuple (optional)#布局(rows, columns)forthe layout of the plot table : boolean, SeriesorDataFrame, default False#如果为正,则选择DataFrame类型的数据并且转换匹配matplotlib的布局。If True, draw a table using the datainthe DataFrameandthe data will be transposed to meet matplotlib’s defaul...
DataFrame的plot方法会在一个subplot中为各列绘制一条线,并自动创建图例(如图9-14所示): 代码语言:javascript 代码运行次数:0 运行 AI代码解释 In [62]: df = pd.DataFrame(np.random.randn(10, 4).cumsum(0), ...: columns=['A', 'B', 'C', 'D'], ...: index=np.arange(0, 100, 10)) ...
线:line plot二维数据,适用于时间序列; 柱状:bar plot二维数据,适用于类别统计; 颜色:heatmap适用于展示第三维度; 数据间存在分布,构成,比较,联系以及变化趋势等关系。对应不一样的关系,选择相应的图形进行展示。 第二步:转换数据,应用函数 数据分析和建模方面的大量编程工作都是用在数据准备的基础上的:加载、清...
Series和DataFrame是Pandas库中主要的两种数据结构,都内置了plot方法,可以绘制图形。 1.Series.plot Series是一个一维数据结构,它由index和value组成,类似于Excel表格中的一列数据,由行号和数据组成。根据这样一列数据,我们可以绘制各种图表,如柱状图、条形图、折线图、饼图等。
在这个例子中,我们首先将’Month’列设置为DataFrame的索引。然后,我们使用Pandas的plot方法绘制条形图。Matplotlib会自动使用索引作为X轴标签。 4. 使用plt.xticks()设置X轴标签 有时,我们可能不想改变DataFrame的结构。在这种情况下,我们可以使用plt.xticks()函数来手动设置X轴标签: ...