简体   繁体   English

表不同于 Editor Power Query 到 Python

[英]table distinct from Editor Power Query to Python

I need to transform a data transformation programm from Editor Power Query to Python.我需要将数据转换程序从 Editor Power Query 转换为 Python。 I am not very good with Editor power Query.我对编辑器电源查询不是很好。

I have a table with 30ish columns, with a task like this:我有一个有 30 列的表,任务如下:

= Table.Distinct(#"Previous task", {"column1"})

When I do this, which row does it take?当我这样做时,它需要哪一行? the first one?第一个? the last one?最后一个? A random one?一个随机的? How can I translate this to Python Pandas, to be sure to have same data?我如何将其翻译为 Python Pandas,以确保具有相同的数据?

Thanks for answer感谢您的回答

By default, I believe Table.Distinct keeps the first row.默认情况下,我相信Table.Distinct保留第一行。

In Pandas, you could use something like:在 Pandas 中,您可以使用以下内容:

df.drop_duplicates(keep='first', inplace=True)

The keep parameter specifies which row you want to keep, and the inplace parameter just makes sure the changes are made to the dataframe itself and not a copy of the dataframe. keep参数指定要保留的行, inplace参数只是确保对 dataframe 本身进行更改,而不是 dataframe 的副本。

See more here on pandas.DataFrame.drop_duplicates .pandas.DataFrame.drop_duplicates上查看更多pandas.DataFrame.drop_duplicates

Also, here's some more information on Table.Distinct and how you can preserve the sort order of a table before performing the operation.此外, 这里还有一些关于Table.Distinct的更多信息,以及如何在执行操作之前保留表的排序顺序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM