如何从 Excel 的特定列和行定义参数?

发布于 2025-01-13 18:22:45 字数 386 浏览 2 评论 0原文

我想从 Excel 文件中获取某些值的列表。

我尝试了这个:

import pandas as pd
df = pd.read_excel('Data.xlsx')

orders = df[['Order']].loc[[4,129]]
print(orders)

我获得了这个解决方案:

        Order
4    18292839
129  83938292

但是我想要获得的解决方案是像这样的值列表中从4到129的顺序:

['18292839',....... ....(其他订单),'83938292']

如果有人可以帮助我,我将非常感激!

I want to obtain a list of certain values from an excel file.

I tried this:

import pandas as pd
df = pd.read_excel('Data.xlsx')

orders = df[['Order']].loc[[4,129]]
print(orders)

I obtained this solution:

        Order
4    18292839
129  83938292

But the solution that I want to obtain is the orders from 4 to 129 in a list on values like this:

['18292839', .............. (other orders), '83938292']

If someone can help me I will be very grateful!

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

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

发布评论

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

评论(1

川水往事 2025-01-20 18:22:45

您可以使用orders.values.tolist()pd.Series转换为list。有关将 DataFramesSeries 转换为 list 的更多信息,您可以阅读 这里。

You can use orders.values.tolist() to convert pd.Series into list. More about converting DataFrames and Series into the list you can read here.

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