Get the App
SLTechnology News&Howtos  ›  Servers  › 

Skills of using Pandas and Docker

Shulou Source: shulou.com Published: 2022-06-01 10:14:42 09月11日 Update

This article introduces the relevant knowledge of "skills in the use of Pandas and Docker". Many people will encounter such a dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Pandas reads headless CSV

We know that CSV usually looks like this:

Where the name,salary,work in the first line is called the header of CSV. Normally, CSV has a header, so it's very convenient when we use pandas to read CSV:

Import pandas as pd df = pd.read_csv ('example.csv') print (df)

The running effect is shown in the following figure:

Sometimes, however, some special CSV files may not have headers. For example, they might look like this:

In this case, if you read directly using pandas, the first row of data becomes a header, as shown in the following figure. But this is obviously not what I want:

In order to solve this problem, there are two solutions. The first method is to open the CSV file with a text editor, manually add the header, and save it. And then read it with pandas.

The second way is to add a parameter, names, when pandas reads, whose value is a list, or header:

Import pandas as pd df = pd.read_csv ('example.csv', names= [' name', 'salary',' work']) print (df)

The running effect is shown in the following figure:

Docker build increases apt-get Speed

When using Docker to build Ubuntu-based images in China, official sources are used by default. For well-known reasons, the speed of building can be slow. If you are directly operating the Ubuntu of the host, we can use vim or graphical interface to modify the source and use the Ali source to improve speed.

What should I do if it is in Docker? We can then use Linux text processing sed, one of the three Musketeers, to modify the source file non-interactively.

Add the following two lines to Docker:

RUN sed-is @ / archive.ubuntu.com/@/mirrors.aliyun.com/@g / etc/apt/sources.list RUN apt-get clea

Its purpose is to replace all archive.ubuntu.com in the / etc/apt/sources.list file with mirrors.aliyun.com. To increase the speed.

This is the end of the introduction to "Pandas and Docker skills". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Speed situation file method use skill skill line content effect text time is in more knowledge run practical special as we all know what you have learned and then Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux Xiaomi Docker Shulou Technology Huawei