How to retrieve the lost Excel file (throw away Excel, teach you how to use Python for visualization

 

1. Python Rookie Tutorial

Pine from Wafeisi quantum bit | official account QbitAI data visualization animation is still done in Excel? Now a simple Python package can be done in minutes! And the generated animation is also silky enough, with a sauce purple effect:

2. Usage of Python for i in range()

This is an installation package developed by a programmer specializing in the Python language, named Pynimate. Currently, it can be installed and used directly through PyPI.

3. Python for loop

To use Pynimate in the user guide, simply import it as nim. After inputting data, Pynimate will use the function Barplot() to create a bar data animation. The input data must be a Pandas data structure.

4. Python while loop statement

(As shown below), where the time column is set as an index, in other words, the index represents the independent variables time, col1, col2, col320121212013112014211.5320152.523.5. The specific code format is as follows: import pandas

5. Function and Usage of Python Strip() Function

As PD Df=pd.read_ CSV (datacsv). set_ For example, to process specific data, the code should look like df=pd.DataFrame ({"time": ["1960 01 01"),.

6. Python set function

1961 01 01 ", 1962 01 01 01"], "Afghanistan": [1,2,3], Angola: [2,3,4], "Albania": [1,2,5], "USA": [5,3,4], "Argentina":

7. Python pow function

[1,4,5],}). set_ In addition, to create a bar data animation, Barplot also has three necessary parameters to note: data, time_ Format and IP_ Freq (Interpolation frequency)

8. Python get() function

Data is the data of a table, so time will not be repeated here_ Format refers to the time and date format of the data index, usually: "% Y -% m -% d" followed by IP_ Freq, which is a key step in the production of animation, makes the animation more smooth and silky through linear interpolation. Generally speaking, not all the original data is suitable for animation. Now a typical video is 24fps, that is, 24 frames per second.

9. Python turn

For example, the data in the table below only has three time points, which can only generate three frames of video. The final animation is only 3/24 seconds in time, col1, col2201213201322201431. At this time, IP_ The freq interpolation (linear) starts to work, and if the interpolation is for a quarter, the resulting data becomes like this:.

10. Python str function

Timecol1col22012-01-011.003.002012-04-011.252.752012-07-011.502.502012-10-011.752.252013-01-012.002.00

2013-04-012.251.752013-07-012.501.502013-10-012.751.252014-01-013.001.00 The specific interpolation time interval depends on the specific data. Generally, when drawing big data, it is set to IP_ Freq=None.

At this point, the data animation can be generated, and the complete code is as follows: from matplotlib import pyplot as plot Import Pandas as PD Import pynimate as nim Df=pd.DataFrame( {

"Time": ["1960 01 01", "1961 01 01", "1962 01 01"], Afghanistan: [1, 2, 3], "Angola"

: [2, 3, 4], Albania: [1, 2, 5], USA: [5,3,4], Argentina: [1, 4, 5], } ). set_ Index(

Time) Cnv=nim. Canvas() Bar=nim. Barplot (df, "% Y -% m -% d", "2d") Bar.set_ Time (callback=lambda i, datafield: datafield. data. index [i]. year) Cnv.add_ Plot (bar) Cnv. animate() PLT. show()

This is the animation effect generated by interpolation for two days.

Finally, there is another issue, which is to save the animation. There are two formats to choose from: gif or mp4. Saving as an animated image is usually done using: cnv. save ("file", 24, "gif"). If you want to save as an mp4, ffmpeg is a good choice as it is the standard editor for saving as an mp4.

Pip install ffmpeg Python or: conda install ffmpeg Of course, Canvas. save() can also be used to save cnv. save ("file", 24, "mp4")

The author introduces Julkar9, a Python/Flutter developer specializing in data analysis and visualization. My little brother said that Pynimate will continue to be updated and is currently receiving feedback from everyone. In the future, functions such as contour maps will also be launched.

He also developed an application called Chatmetry, which is also related to data statistics. It is a robot application used to create WhatsApp chat statistics data. This program can generate various statistical information from exported chats, support personal and group chats, and is completely offline, neither saved nor shared.

Portal: https://julkaar9.github.io/pynimate/ - End - QbitAI · Headlines Sign up to Follow Us, Get the First News of Frontier Technology Trends

为您推荐

How to retrieve the lost Excel file (throw away Excel, teach you how to use Python for visualization

How to retrieve the lost Excel file (throw away Excel, teach you how to use Python for visualization

Pine 发自 凹非寺。数据可视化动画还在用Excel做?这是一位专攻Python语言的程序员开发的安装包,名叫Pynimate...

2023-06-04 栏目:编程控

当前非电脑浏览器正常宽度,请使用移动设备访问本站!