Home > Backend Development > Golang > golang must reach the first n lines

golang must reach the first n lines

PHPz
Release: 2024-02-09 13:06:08
forward
1104 people have browsed it

golang 必须达到前 n 行

Golang is a powerful programming language that is widely used in the development of large-scale systems. When using golang, mastering the skills of the first n lines of code is essential. By understanding and adeptly using these key codes, developers can more efficiently write clear, reliable programs. In this article, PHP editor Xigua will introduce you in detail the importance of golang to achieve the first n lines, and share some practical tips and suggestions to help you give full play to the advantages of golang. Whether you are a beginner or an experienced developer, you can benefit from it. Let’s take a closer look!

Question content

I'm converting my project from python to golang, but I'm stuck on using gota as the equivalent of pandas dataframe.

In pandas, I use df.nlargest(20, ['change']) to extract the highest value from the dataset, but I can't seem to find the equivalent.

I can sort the data using the following

sorted := valuesDf.Arrange(dataframe.RevSort("Change"))
Copy after login

However, I still need a way to select the first 20 rows of data because next I want to calculate the average of this updated dataframe.

I will use the .mean() function to achieve this

Does anyone know a way to select the first 20 rows?

Solution

There is no func in the same function. But you can create your own.

sorted := dataframe.arrange(
    dataframe.sort("change"),
)
Copy after login

Here we sort by field.

sub := sorted.Subset([]int{0, 20})
Copy after login

Now we get the top 20 from this sorted dataframe.

The above is the detailed content of golang must reach the first n lines. For more information, please follow other related articles on the PHP Chinese website!

source:stackoverflow.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template