简体   繁体   English

如何将 csv 文件中的特定列导入 python?

[英]How can I import specific columns from csv file to python?

python python

what syntax should i use in importing only the columns of 'location', specifically two countries only,'date', 'total_cases', 'new_cases', 'total_deaths', 'new_deaths'.我应该使用什么语法只导入“位置”的列,特别是两个国家,“日期”,“total_cases”,“new_cases”,“total_deaths”,“new_deaths”。

I recommend using the pandas library for handling the csv.我建议使用 pandas 库来处理 csv。

You can use read_csv() to skip/select rows based on a conditional format.您可以使用read_csv()根据条件格式跳过/选择行。

Here is a link with a step-by-step guide on how to do this:这是一个链接,其中包含有关如何执行此操作的分步指南:

https://datascientyst.com/read_csv-skip-rows-condition-values-pandas/amp/ https://datascientyst.com/read_csv-skip-rows-condition-values-pandas/amp/

Alternatively, you can import the entire .csv file and then delete certain rows based on a condition, as seen in the link below:或者,您可以导入整个.csv文件,然后根据条件删除某些行,如下面的链接所示:

https://towardsdatascience.com/delete-row-from-pandas-dataframes-based-on-column-value-4b18bb1eb602 https://towardsdatascience.com/delete-row-from-pandas-dataframes-based-on-column-value-4b18bb1eb602

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

相关问题 如何在python中从CSV文件中打印选定的列 - How can I print selected columns from a CSV file in python python(numpy):如何从CSV文件读取特定的列? - python(numpy): how to read specific columns from CSV file? 如何在python中从csv文件绘制两个特定的列 - How to plot two specific columns from a csv file in python 如何 plot 或在 CSV 文件中显示特定列? - How Can I plot or show specific Columns in a CSV File? 如何散列 csv 文件中的特定列? - How do I hash specific columns from a csv file? 如何在python中导入csv文件中变量的值? - How can I import the values of a variable in a csv file, in python? 如何使用 python 和 Z3A43B4F88325D24022C0EFA9C 库从 csv 文件导入二维 arrays? - How can i import two dimensional arrays from a csv file using python and the pandas library? 如何根据来自其他两列的两组描述符从 CSV 文件的列中打印 Python 3.9 中的一组特定数据? - How can I print a specific set of data in Python 3.9, from a column of a CSV file based on two sets of descriptors from two other columns? 如何从 python 中的另一个文件夹导入 csv? - How can I import a csv from another folder in python? 如何在 Python 中的 csv 文件的特定列中测试条件 - How can I test a conditional in a specific column of a csv file in Python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM