Wonderful, the method and technique of Pandas loading data are really delicious

Hello everyone, I believe that my friends will have heard or used pandas more or less in the process of learning python data analysis

pandas is an extension library of python, often used for data analysis

Today, Xianyu will introduce several methods and techniques for importing data from pandas

Get CSV data from URL

Regarding pandas importing csv data, the following method is used

picture

But this method can fetch CSV data from URL via HTTP

For example, the following example will show how to get the csv file through the URL

picture

picture

Obtaining CSV data through the URL can save the step of saving the CSV file locally first

Get HTML table from website

pandas.read_html()Used to get the table data in the HTML file (that is, <table>the tabular data of the label)

Let's look at the following example

picture

picture

pandas.read_html()A simple crawler can be realized by

JSON data formatting

Sometimes when we process JSON data, we find that JSON data is usually nested in multiple layers

If we want to convert JSON data into tabular data to make it flat, we can use the following method to achieve it

picture

See the example below

picture

The result is as follows

picture

Next, let's try reading more complex JSON data, which has nested lists and dictionaries

picture

The result is as follows

picture

Get data from the clipboard

The pandas read_clipboard()method can get any data stored on the clipboard

Suppose you want to copy and paste the data from the Internet to the local, then read_clipboard()you can directly read the contents of the clipboard with the method of pandas

By default, regular expressions are used \s+as delimiters for separating values ​​(that is, matching one or more blank characters such as spaces, tabs, and newlines as delimiters), and then split the data on the clipboard into tabular data

picture

Guess you like

Origin blog.csdn.net/2301_78285120/article/details/130959153