In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article will explain in detail about python learning and data mining need to master the terminal command, Xiaobian think quite practical, so share to you as a reference, I hope you can read this article after harvest.
1、wget
The wget utility is used to download files from remote servers. You can use it to download datasets, as long as you know the URL, you can use the wget command to download it, I take the following url as an example:
https://raw.githubusercontent.com/jbrownlee/Datasets/master/airline-passengers.csv
If you are on a Mac and wget is not available by default, run brew install wget from the terminal to install it. Now that the dataset has been downloaded, let's move on to some basic exploration.
2、head
If you are a Python user, this will feel familiar. Otherwise, the head command is used to print the first N lines of the file. Print 10 lines by default:
If you want a different number, say 3, you can use the-n argument. The complete command is:
head -n 3 airline-passengers.csv3、tail
The tail command is very similar to the head command, except that it prints the last N lines.
Print 10 lines by default:
As with head, you can also specify the number of rows to print using the-n parameter.
We've covered the basics now, so let's move on to something more interesting.
4、wc
Sometimes you wonder how many data points there are in a file. No need to open it and manually scroll to the bottom. A simple command can save you some time:
In summary, the airline-passengers.csv file contains 144 lines.
5、grep
This command is used to process text and can match strings and regular expressions. We'll use it to extract only lines that contain the string "1949." It's a simple dataset, so we won't have any problems. By default, the grep command prints the results, but we can save them to another CSV file:
6、cat
To verify that the previous operation succeeded, we can use the cat command. It is used to print the entire file to the shell. You can also use it to combine files and more, but that's the subject of another time.
Now, let's print the whole file. The data is aggregated by month, so there should be a total of 12 rows:
7、find
You can use the find command to search for files and folders. For example, execute the following command to print all CSV files in the current directory (specified by dots) to the shell:
An asterisk (*) indicates that the file name doesn't matter as long as it ends with ".csv."
8、sort
As the name suggests, the sort command can be used to sort the contents of files by some criteria. For example, the following command sorts the dataset in ascending order of passenger count:
The-k2 parameter specifies that the second column is sorted. If you want to sort files in descending order, you can specify an additional-r parameter:
9、nano
While not technically a shell command, executing it opens the Nano editor. Here's how to create Python files:
nano pyfile.py
Here, let's write some simple Python code:
You can write any Python code in the editor and do analysis that is too complex for simple terminal commands. Once done, you can run Python files:
10、Variables
Let's end today's article with Variables. They can come in handy, for example, when file paths get long, or when you need to use them multiple times.
Here's how to declare two string variables and rename the airline-passengers-1949.csv file to new.csv using the mv command:
The ls command is used to list files in a directory, and as we can see, the rename operation succeeds.
About "Python learning and data mining need to master what terminal commands" This article is shared here, I hope the above content can be of some help to everyone, so that you can learn more knowledge, if you think the article is good, please share it to let more people see.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.