拆分废纸用熊猫列入列表

发布于 2025-02-10 06:45:21 字数 366 浏览 2 评论 0原文

所以我在这里有一条基本的3行。在我打印航空公司[3]时给我提供所需的信息,但是如果我将其放入for for for for for'in in Airlines [3]中:'它只会打印出航空公司和目的地。我想把所有航空公司都列入自己的列表,我也希望所有目的地都在他们自己的列表中。

import pandas as pd
airlines = pd.read_html('https://en.wikipedia.org/wiki/Tan_Son_Nhat_International_Airport')

# Prints off table
print(airlines[3])


airlines_list = []
destination_list = []

So I have a basic 3 lines here. Gives me the info I want when I print airlines[3] but if I put it in a for loop like 'for i in airlines[3]:' it only prints out Airlines and Destinations. I want to take all the airlines put them into their own list and I want all the destinations in their own list too.

import pandas as pd
airlines = pd.read_html('https://en.wikipedia.org/wiki/Tan_Son_Nhat_International_Airport')

# Prints off table
print(airlines[3])


airlines_list = []
destination_list = []

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

﹂绝世的画 2025-02-17 06:45:21

航空公司[3]是Pandas DataFrame。使用以下命令创建单独的列表:

In [1606]: df = airlines[3]

In [1607]: airlines_list = df['Airlines'].tolist()

In [1609]: destination_list = df['Destinations'].tolist()

airlines[3] is a pandas dataframe. Use below commands to create separate lists:

In [1606]: df = airlines[3]

In [1607]: airlines_list = df['Airlines'].tolist()

In [1609]: destination_list = df['Destinations'].tolist()
最后的乘客 2025-02-17 06:45:21

如果您不想在其中任何一个列表中考虑重复项,则可以使用set()

list(set(df['Destinations']))

In case you want to not consider duplicates in either of those list , you can use set()

list(set(df['Destinations']))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文