Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize the basic drawing of data Visualization by Pandas

Shulou Source: shulou.com Published: 2022-06-02 09:29:49 09月17日 Update

Editor to share with you how to achieve Pandas data visualization of the basic drawing, I hope you will learn something after reading this article, let's discuss it together!

1. Environment

IDE: jupyter notebook

Anaconda 3.X

2. Based on matplotlib

Import matplotlib.pyplot as plt

Note: import matplotlib.pyplot

Import matplotlib

Matplotlib.style.use ('ggplot')

% matplotlib inline

Note: use ggplot style and draw in jupyter notebook

Import pandas as pd

Import numpy as np

Ts = pd.Series (np.random.randn (1000), index=pd.date_range ('1max), periods=1000))

Ts.plot ()

Note: use pandas to create a Series (sequence) with randomly generated 1000 standard normal distribution values and an index of 1000 time series values starting from 2000-1-1.

Then draw by default using plot. As you can see, the following figure is very irregular because the two adjacent values are also random in size.

Import pandas as pd

Import numpy as np

Ts = pd.Series (np.random.randn (1000), index=pd.date_range ('1max), periods=1000))

Ts = ts.cumsum ()

Ts.plot ()

Note: ts = ts.cumsum () is added here, which means to return the cumulative value. In time series analysis, the cumulative value curve is often observed to observe the trend.

This cumulative value seems to be more regular.

Df = pd.DataFrame (np.random.randn (1000, 4), index=ts.index, columns=list ('ABCD'))

Df = df.cumsum ()

Plt.figure ()

Df.plot ()

Note: here you use pandas to create a DataFrame (data box, a bit like an excel table), so why not use the Series just now? Because four sets of data are created in DataFrame, these four sets of data are randomly generated 1000 standard normal distribution values, the index is 1000 time series values starting from 2000-1-1, and also calculate their cumulative values and draw pictures.

Df3 = pd.DataFrame (np.random.randn (1000, 2), columns= ['baked,' C']) .cumsum ()

Df3 ['A'] = pd.Series (list (range (len (df)

Df3.plot (x, y, y, etc.)

Note: two sets of data, also 1000 standard normal distributions, are created using DataFrame, named B and C respectively (column names in line excel). And find the cumulative value, and then in the original df (abbreviation of DataFrame) (here the name is df3), add a list of values named A Magi An is 0-999 (using the length of df3 is 1000, and then range is trapped list to generate a column number, as the x axis), the y axis is B column data (cumulative value), c column data is not used in the final drawing.

Finally, the Pandas basic drawing plot is completed!

After reading this article, I believe you have a certain understanding of "how to realize the basic drawing of data visualization in Pandas". If you want to know more about it, you are welcome to follow the industry information channel. Thank you for reading!

Tags: Data series drawing foundation time series time series standard normal distribution generation visualization article index observation irregularity following picture no two name picture size Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Redmi Shulou Tech Info Docker vpn