In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains why Python needs the DataFrame type of Pandas. Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn why Python needs the DataFrame type of Pandas.
1. Problem description
Suppose there is a need to collect basic movie data on a movie website. The fields include movie name, movie URL connection address and movie score. Imagine what data type should be selected to store this data?
The first thing you might think of is the list () type, and you'll soon write the following code:
Videos = [] item = ['the Devil Child of Najai', 'http://www.videos.com',' 9.9'] videos.append (item)
# [['the Devil Boy of Najai', 'http://www.videos.com',' 9.9]]
Although you can store this data, it will be very troublesome to find and modify some operations based on this data, such as sorting by score, super-finding records containing specific keywords, and so on. The same problem is faced with numpy.ndarray ().
The form of data described above is a common kind of data that needs to be stored and processed, but neither list () nor numpy.ndarray () can handle the data well, so we need a new and more convenient data type, which is the DataFrame type provided to us by pandas.
2. DataFrame type of Pandas
Pandas is a commonly used third-party library in Python development, and DataFrame is the most commonly used data type, which is a container for storing data. The common ones to store data in python are list () and the more powerful numpy.ndarray () in numpy, but why use DataFrame?
First, write the code to collect the basic data of the movie:
Df = pandas.DataFrame (columns= ['video_name',' video_url', 'video_score']) for i in range (1112): url =' https://www.meiju.net/search.php?page={}&searchtype=5&tid=2'.format(i) soup = BeautifulSoup (requests.get (url). Content 'html.parser') for item in soup.select (' div.hy-video-list li > a'): row = edict () row.video_name = item ['title'] row.video_url = item [' href'] score_tag = item.select_one ('span.score') if score_tag is not None: row.video_score = score _ tag.text df = df.append (row Ignore_index=True)
With the DataFrame type, what can we do?
You can quickly sort the data by score:
Df.sort_values ('video_score', ascending=False)
In addition to the above, there are many more powerful features and methods, and subsequent articles will continue to cover them based on a number of cases.
3. Conclusion
This paper introduces how to use the DataFrame type of Pandas to store the data of movie data set, and introduces the very convenient data operation provided by DataFrame. At this point, I believe you have a deeper understanding of "why Python needs the DataFrame type of Pandas". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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.