当包含 1 或 2 个其他命名属性时,在 Python 中显示 csv 文件的属性
我是 python 新手,非常感谢您的帮助。我在 Excel 中创建了一个汽车属性文件,并将其另存为 csv 文件,名为 cars.csv,如下所示:
Car make, colour, price, number of seats, automatic, petrol
Ford, black, 40000,5,yes,no
Tesla, white, 90000,4,yes,no
在标题之后,我有 20 行包含不同的汽车及其属性。
有人可以帮助我用 python 代码返回所有具有 4 个座位的汽车品牌,或者说成本 40000,或者说这两个属性吗?谢谢。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用
Pandas
:过滤您的数据框
您还可以阅读此
You can use
Pandas
:Filter your dataframe
You can also read this
如果您不想使用任何库,可以使用此方法
If you dont want to use any library you can use this approach
您应该在这里使用 pandas.loc[] 函数。如果使用 pandas 加载 csv,则可以使用 loc 函数仅选择符合条件的行。
希望这能回答您的问题。
快乐编码!!
You should use the pandas.loc[] function here. If you load the csv with pandas, you can use the loc function to select only the rows that match your conditions.
Hope this answers your question.
Happy coding!!