python配合pandas实现数据分析(pythonpandas数据分析2)
python配合pandas实现数据分析(pythonpandas数据分析2)df = pd.DataFrame(np.random.randn(50 4) index=np.arange(50) columns=list("ABCD")) df.plot.bar(y='B' color='DarkBlue' label='Class1') Out[5]:<matplotlib.axes._subplots.AxesSubplot at 0x1e35ce6e668>In [5]:<matplotlib.axes._subplots.AxesSubplot at 0x1e35acc5f28>In [3]:df = pd.DataFrame(np.random.randn(1000 4) index=np.arange(1000) columns=list("ABCD
除了plot,经常会用到还有scatter,这个会显示散点图,首先给大家说一下在 pandas 中有多少种方法 bar hist box kde area scatter hexbin
In [1]:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
In [2]:
# 随机生成1000个数据
df = pd.Series(np.random.randn(1000) index=np.arange(1000) name='d')
df.plot()
Out[2]:
<matplotlib.axes._subplots.AxesSubplot at 0x1e35acc5f28>
In [3]:
df = pd.DataFrame(np.random.randn(1000 4) index=np.arange(1000) columns=list("ABCD"))
df = df.cumsum()
df.plot()
plt.show()
In [4]:
ax = df.plot.scatter(x='A' y='B' color='DarkBlue' label='Class1')
df.plot.scatter(x='A' y='C' color='LightGreen' label='Class2' ax= ax)
Out[4]:
<matplotlib.axes._subplots.AxesSubplot at 0x1e35ce6e668>
In [5]:
df = pd.DataFrame(np.random.randn(50 4) index=np.arange(50) columns=list("ABCD"))
df.plot.bar(y='B' color='DarkBlue' label='Class1')
Out[5]:
<matplotlib.axes._subplots.AxesSubplot at 0x1e35cee7e80>
In [6]:
df['A'].plot.hist()
Out[6]:
<matplotlib.axes._subplots.AxesSubplot at 0x1e35ce2a9e8>
In [7]:
df['A'].plot.box()
Out[7]:
<matplotlib.axes._subplots.AxesSubplot at 0x1e35d035f98>
In [8]:
df['A'].plot.kde()
Out[8]:
<matplotlib.axes._subplots.AxesSubplot at 0x1e35ce2afd0>
In [9]:
df.plot.area(stacked=False)
Out[9]:
<matplotlib.axes._subplots.AxesSubplot at 0x1e366bcd860>
In [10]:
ax = df.plot.area(y='B' stacked=False)
In [11]:
ax = df.plot.hexbin(x='A' y='B' gridsize=20)