Data visualization Pandas--

1 Introduction

First, we need to use the import module, besides pandas, we also need to use numpy to generate some data, matplotlib used in this section is only used to show pictures of that plt.show ().

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

2.Series Visualization

This is a linear data, we randomly generated 1000 data, Series default index is an integer from 0 to start, but here I explicit assignment in order to let everyone see more clearly

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

data = pd.Series(np.random.randn(100),index=np.arange(100))  # 随机生成1000个数据服从标准正太分布
data.cumsum()    # 为了方便观看效果, 我们累加这个数据
data.plot()    # pandas 数据可以直接观看其可视化形式
plt.show()

Here Insert Picture Description
Matplotlib familiar friends know if you need a plot data, we can use plt.plot (x =, y =), the data x, y as a parameter deposit into, but the data itself is a data, so we can directly plot.

3.Dataframe Visualization

We generate DataFrame a 100 * 4, and they accumulate

data = pd.DataFrame(np.random.randn(100,4),index=np.arange(100),columns=list("ABCD"))
data.cumsum()
print(data)
data.plot()
plt.show()

Here Insert Picture Description
This is what we just created 4 column of data, because there are four sets of data, the four sets of data will come out each plot.

4. Scatter painting

Mainly talk about the plot and scatter. Scatter only because of x, y two properties, we can give our respective x, y specified data

ax = data.plot.scatter(x='A',y='B',color='DarkBlue',label='Class1')
# 将之下这个 data 画在上一个 ax 上面
data.plot.scatter(x='A',y='C',color='LightGreen',label='Class2',ax=ax)
plt.show()

Here Insert Picture Description

Published 144 original articles · won praise 388 · views 20000 +

Guess you like

Origin blog.csdn.net/weixin_37763870/article/details/104933227