Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of pandas Intelligent Visualization assisted by Python Library

2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

Python library to help pandas intelligent visualization example analysis, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can get something.

Pandas is the core library for data processing, it can also carry out simple visualization, drawing scattered points, broken lines, histograms and other basic charts are easy.

The visualization method that comes with Pandas is based on the function interface of matplotlib and can be statically displayed in Jupyter.

This time, we introduce a visualization tool-LUX, which can automatically convert DataFrame data into statistical charts, allowing you to see correlation, distribution, frequency and other information at a glance.

LUX interacts in Jupyter Notebook or Lab, and charts and data can be displayed synchronously.

Project address: https:// github.com/lux-org/lux

Use LUX

Take the following dataset (US university information table) as an example:

# Import pandas and lux library import pandas as pd import lux # load data df = pd.read_excel ("C:\\ Users\\ zii\\ Documents\\ USA_College.xlsx") df

The data read is as follows:

In addition to the data table displayed, you will also see a button on the dataset for data / chart exchange and display.

So you only need to import the lux library and you can use the chart function directly.

You can see that there are three types of charts below, which represent the statistical meaning of correlation, histogram distribution, and frequency of events.

In addition to the visual exploration of the whole table, you can also study the relationships between specific variables.

For example, I want to see the correlation between the average SAT and the median income.

Df.intent = ['SAT average', 'median income'] df

The table on the left shows the overall distribution of the two variables, and the right shows the distribution with filtering conditions.

Export chart

LUX supports the export of charts, which can export not only chart files, but also corresponding matplotlib and altair codes.

First select one or more charts and click the Export button.

You can directly display the selected chart separately:

Hongmeng official Strategic Cooperation to build HarmonyOS Technology Community

Export html df.save_as_html ('hpi.html')

Export matplotlib code

Vis = df.exported print (vis [0] .to _ matplotlib ())

Hongmeng official Strategic Cooperation to build HarmonyOS Technology Community

Export altair code

Vis = df.exported print (vis [0] .to _ Altair ())

The exported code can be run directly:

Import altair as alt chart = alt.Chart (df). Mark_circle (). Encode (x=alt.X ('SAT average', scale=alt.Scale (domain= (666,1534)), type='quantitative', axis=alt.Axis (title='SAT average')), y=alt.Y ('median income', scale=alt.Scale (domain= (20200, 125600)), type='quantitative' Axis=alt.Axis (median title=' income')) chart = chart.configure_mark (tooltip=alt.TooltipContent ('encoding')) # Setting tooltip as non-null chart = chart.interactive () # Enable Zooming and Panning chart = chart.encode (color=alt.Color (' highest degree', type='nominal')) chart = chart.configure_title (fontWeight=500,fontSize=13,font='Helvetica Neue') chart = chart.configure_axis (titleFontWeight=500,titleFontSize=11,titleFont='Helvetica Neue', labelFontWeight=400,labelFontSize=8,labelFont='Helvetica Neue') LabelColor='#505050') chart = chart.configure_legend (titleFontWeight=500,titleFontSize=10,titleFont='Helvetica Neue', labelFontWeight=400,labelFontSize=8,labelFont='Helvetica Neue') chart = chart.properties (width=160,height=150) chart installation Settings

The lux installation process, like other libraries, can be installed through pip or conda and entered directly on the command line:

Pip install lux-api

Or

Conda install-c conda-forge lux-api

Because lux is typically used in the Jupyter ecosystem, you need to install and activate the luxwidget extension to display the interactive window.

If you are using it in Jupyter Notebook or VSCode, activate the extension using the following code:

Jupyter nbextension install-py luxwidget jupyter nbextension enable-py luxwidget

If you are using Jupyter Lab, activate the lab extension:

Jupyter labextension install @ jupyter-widgets/jupyterlab-manager jupyter labextension install luxwidget

LUX is a good data visualization analysis tool, which can intelligently assist Pandas to do data exploration, saving a lot of unnecessary operations.

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report