Why use Python for data analysis? Just 4 codes to draw the map

Why Python

First talk about why you must use Python or R language for data analysis. There are so many programming languages. Java and PHP are very mature, but why did many people choose to use Python language in the field of data analysis in the recent Heat?

Data analysis is just a requirement. In theory, any language can meet any needs, but it is just a matter of trouble and simplicity. The Python language was born quite early. Its first version was published 26 years ago. It was once (or currently) used for web development, but in terms of popularity, it is far from Java and PHP. . The East did not shine brightly in the West. In these 20 years of failure with Java, Python has developed a unique martial arts that is far beyond Java and PHP (which, of course, is not catching up. It is not yet clear) . You have to say to be a blog site, Python's specialty is not here, PHP and Java are also minutes of things. You have to say to be a BBS website, be an e-commerce website, and PHP will come to you. Python competes with Java or PHP in these areas. Basically, it is the rhythm of death. Although there is a framework like django, it is far less popular than other languages. However, behind these years of silent failures, a group of researchers used Python to dry out some horrific artifacts, making Python a point beyond the R language in the field of data research.

Jupyter

First, the first artifact is Jupyter. If you are using it for the first time, it may not be clear what its developers are doing with such a ghost thing. It is also not a blog system. It is not like a web server, but it is useful. Because the first thing we think about traditional web development is the public, you need to serve thousands of browsers to make a server. Of course, Jupyter can also serve many browsers, but it is more convenient for researchers and researchers. It is simply too convenient. You write the code directly in the input box as if it was an article, and then you can directly see the result of this code on this page. You can modify it at any time and display it at random. Enhanced version, after all, Markdown can only display text, add up to some pictures, and Jupyter can run Python code directly. Of course, some people are trying to run PHP or Java code in Jupyter, but it is obviously not a climate. Because the Python language is inherently a scripting language, the only hopeful future porting is Javascript, which is also a scripting language. The advantage of a scripting language is that it does not compile, one result per line. Looking at the history of computer language development is a process from complexity to simplicity. C language needs to compile and link to run. Java only needs javac to combine compilation and linking. PHP is simpler, and it will run directly. It's all saved. But it's not straightforward, because you have to write a .php file to save it before you can run it. In Python and other scripting languages, you can run it directly in the shell, but the biggest problem is that the run can run, you can't save it, and you save it. Just like the traditional way, look for an editor, or vi, run as a file. The biggest advantage of Jupyter is that it is itself a shell environment and can run scripts, but it also automatically saves the script code for you. Not only saves the script code, but all comments inserted in the script code are not ordinary comments. Instead, various formatted Markdowns are saved for you and can be modified at any time. Therefore, it combines the advantages of a script shell and a file management system. From then on, you can develop Python code without having to write the code in the IDE first, and then go to the terminal and run it directly on a web page. Java has such a tool? PHP has such a tool? No, so we must choose Python.

Pandas

The second artifact is Pandas. If I let you read a csv file and then ask for the mean, maximum, minimum, variance of each column of data, how do you do it in Java or PHP? You must first fopen a file, then read it line by line, give it the entire data structure, and then make a round of calculations, and finally you may have to fclose the file. In short, the code is awkward. Because Python language has Pandas artifact, one line of code to get:

Df = pd.read_csv('a.csv')

OK, since then, df is the DataFrame, which itself is a powerful data structure, it can also be understood as a table in the mysql database, a variety of additions and deletions to change the search sum, the average is a line of code Things. So there is such a powerful library. What are the reasons for researchers to choose Java?

Scikit-learn

The third artifact scikit-learn, generally abbreviated as sklearn, various machine learning algorithms, basically as long as you can think of, linear regression, logistic regression, SVM, random forest, nearest neighbor, and so on, all kinds of algorithms all in this Inside (http://scikit-learn.org/stable/user_guide.html), in short, only you can't think of it, without it, you can't do it. So this is why playing machine learning requires Python. Did you give me a library of Java or PHP with such a variety of algorithms?

Matplotlib

The fourth artifact is matplotlib. If I ask you to draw a picture based on the information in the csv file above, what should I do in Java? Of course, you will go to the third-party plug-in library, and then it is a toss, finally figure out, then compile, and then run. What if I want to change the color? What if I asked to draw a map? If you want to draw a heat map? The trouble is not a star, but for matplotlib, it is a piece of cake. The simple histogram does not say, the following focuses on how to use matplotlib to draw a Chinese map with Basemap.

Install Basemap

Install the appropriate components first. I assume you have installed Python, Jupyter, and so on. If it is not installed, try brew install python3 and brew install jupyter. There are many tutorials online.

Then you need to use pip3 to install a lot of libraries that we may need to use below. But because we want to use a library called Basemap, and this library can't be installed with a simple pip3 install, there are a few more steps:

Brew install geos pip3 install https://github.com/matplotlib/basemap/archive/v1.1.0.tar.gz

Start drawing

After starting Jupyter, we started with the simplest code. First draw a map of the world:

Import matplotlib.pyplot as pltfrom mpl_toolkits.basemap import Basemapplt.figure(figsize=(16,8))m = Basemap()m.drawcoastlines()plt.show()

The first two lines introduce the corresponding library, the real code is 4 lines, simple enough. Line 1 may not even be written, it defines the size of the graph. On line 2 we create a map, line 3 draws the coastline, and line 4 shows this map, which is this:

Why use Python for data analysis? Just 4 codes to draw the map

Do you draw a map out of Java's 4 lines of code?

Then we start to draw the country and it is a line of code:

M.drawcountries(linewidth=1.5)

It becomes this:

Why use Python for data analysis? Just 4 codes to draw the map

Is it possible to use Java? Is it possible to use PHP?

If we want to display a map of China, we only need to specify the latitude and longitude when we create the Basemap:

m = Basemap (llcrnrlon=73, llcrnrlat=18, urcrnrlon=135, urcrnrlat=53)

Then you get a map of China:

Why use Python for data analysis? Just 4 codes to draw the map

It seems a bit distorted, because we did not add any reason for the projection. Basemap provides 24 different projection methods. You can try one by one. The more commonly used is the Lambert projection. Let's add:

m = Basemap (llcrnrlon=77, llcrnrlat=14, urcrnrlon=140, urcrnrlat=51, projection='lcc', lat_1=33, lat_2=45, lon_0=100)

This time it finally looks normal:

Why use Python for data analysis? Just 4 codes to draw the map

What do we want to do with the borders of the province? Basemap default package does not have Chinese provinces, only the United States, after all, Americans do it. But fortunately the world is very big. There are specialized international organizations doing this. Here (https://gadm.org/download_country_v3.html) you can download the administrative section shape file of any country in the world, and then we add it to it. on:

M.readshapefile('CHN_adm_shp/CHN_adm1', 'states', drawbounds=True)

Then you get the following picture:

Why use Python for data analysis? Just 4 codes to draw the map

Later, you can change colors in the past, write numbers, and leave them to you. In short, what I want to say is that it's really easy to draw maps with Python.

Finally, for Java and PHP, make a few words: The division of labor is different. Although Java and PHP are not very convenient for doing such digital research, they are still very suitable for web development. Python is not suitable in this respect. So the usual practice is: First use Python to verify the algorithm, after a series of complex calculations, after the algorithm is determined, when you want to apply to the web, then use Java or PHP to rewrite the final conclusion, so that Can make full use of the advantages of various languages.

LED Par can

LED PAR LIGHT Series

54X3W rgbw; 18x12w RGBW;24x12w RGBW is hot selling in the market. It have waterproof and non-waterproof

Features:

  • RGBWA+UV color, 6-in-1 LEDs, excellent color mixing
  • quiet working, suitable for quiet applications like theater, studio,etc
  • suitable for events where indoor/outdoor flexibility is needed

  • Adjustable PWM (Pulse Width Modulation) to avoid flickering on camera
  • Advanced optics provide exceptional color mixing and high efficiency
  • Smooth dimming curves for eliminate flicker and choppiness in fades


Our company have 13 years experience of LED Display and Stage Lights , our company mainly produce Indoor Rental LED Display, Outdoor Rental LED Display, Transparent LED Display,Indoor Fixed Indoor LED Display, Outdoor Fixed LED Display, Poster LED Display , Dance LED Display ... In additional, we also produce stage lights, such as beam lights Series, moving head lights Series, LED Par Light Series and son on...

LED Par Light Series,Led Par Can Lights,Par Can,Led Par Stage Light

Guangzhou Chengwen Photoelectric Technology co.,ltd , https://www.cwledpanel.com

Posted on