Is there a in built method from python csv module to enumerate all possible value for a specific column?

Apoorva sahay

I have a csv file which has many columns. Now my requirement is to find all possible value that are present for that specific column.

Is there any built in function in python that helps me to get these values.

Mike Müller

You can us pandas.

Example file many_cols.csv:

col1,col2,col3
1,10,100
1,20,100
2,10,100
3,30,100

Find unique values per column:

>>> import pandas as pd
>>> df = pd.read_csv('many_cols.csv')
>>> df.col1.drop_duplicates().tolist()
[1, 2, 3]
>>> df['col2'].drop_duplicates().tolist()
[10, 20, 30]
>>> df['col3'].drop_duplicates().tolist()
[100]

For all columns:

import pandas as pd

df = pd.read_csv('many_cols.csv')

for col in df.columns:
    print(col, df[col].drop_duplicates().tolist())

Output:

col1 [1, 2, 3]
col2 [10, 20, 30]
col3 [100]

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Is there a built in Kotlin method to apply void function to value?

来自分类Dev

Python PANDAS: Drop All Rows After First Occurrence of Column Value

来自分类Dev

Is it possible to reload a python module as something?

来自分类Dev

Creating a column to enumerate a set of events

来自分类Dev

How to ORDER BY count of rows with specific column value

来自分类Dev

How to empty a numeric value from a form built with WTForm

来自分类Dev

Reading a specific line from CSV file

来自分类Dev

Get data from a specific column in a TableView QML

来自分类Dev

How to enumerate key value pairs of a bundle

来自分类Dev

Common Lisp中的Python enumerate()模拟

来自分类Dev

使用 enumerate 打开 python 中的文件

来自分类Dev

With specific dates AND times in a database column, how do I query for all records on a specific day?

来自分类Dev

Python import module from导入的模块问题

来自分类Dev

Is it possible to pass the sum of a column from an HTML table on a DIFFERENT website to a db?

来自分类Dev

get all possible combinations of k elements from a list

来自分类Dev

Hide all products with a specific stock status from WooCommerce catalog

来自分类Dev

How to remove all characters from a string before a specific character

来自分类Dev

Python 2.7: Select specific character from string

来自分类Dev

Force a Linux kernel module to be compiled as a module instead of built-in

来自分类Dev

Is it possible to get String value back from its hash code?

来自分类Dev

return value from possible type in std::variant through std::visit

来自分类Dev

Python CSV find string and pass column number to variable

来自分类Dev

Reading data from a CSV file in Python

来自分类Dev

Python pandas.DataFrame.from_csv

来自分类Dev

Why is it not possible in python to have an objects method return a tuple as argument in a new objects __init__ method?

来自分类Dev

Get the objects with the maximum value for a specific property from a list using LINQ

来自分类Dev

python更新csv文件,条件为column2从column1开始

来自分类Dev

在python中使用enumerate()时从列表中删除元素

来自分类Dev

使用python中的enumerate()访问列表中的“操作”对象

Related 相关文章

  1. 1

    Is there a built in Kotlin method to apply void function to value?

  2. 2

    Python PANDAS: Drop All Rows After First Occurrence of Column Value

  3. 3

    Is it possible to reload a python module as something?

  4. 4

    Creating a column to enumerate a set of events

  5. 5

    How to ORDER BY count of rows with specific column value

  6. 6

    How to empty a numeric value from a form built with WTForm

  7. 7

    Reading a specific line from CSV file

  8. 8

    Get data from a specific column in a TableView QML

  9. 9

    How to enumerate key value pairs of a bundle

  10. 10

    Common Lisp中的Python enumerate()模拟

  11. 11

    使用 enumerate 打开 python 中的文件

  12. 12

    With specific dates AND times in a database column, how do I query for all records on a specific day?

  13. 13

    Python import module from导入的模块问题

  14. 14

    Is it possible to pass the sum of a column from an HTML table on a DIFFERENT website to a db?

  15. 15

    get all possible combinations of k elements from a list

  16. 16

    Hide all products with a specific stock status from WooCommerce catalog

  17. 17

    How to remove all characters from a string before a specific character

  18. 18

    Python 2.7: Select specific character from string

  19. 19

    Force a Linux kernel module to be compiled as a module instead of built-in

  20. 20

    Is it possible to get String value back from its hash code?

  21. 21

    return value from possible type in std::variant through std::visit

  22. 22

    Python CSV find string and pass column number to variable

  23. 23

    Reading data from a CSV file in Python

  24. 24

    Python pandas.DataFrame.from_csv

  25. 25

    Why is it not possible in python to have an objects method return a tuple as argument in a new objects __init__ method?

  26. 26

    Get the objects with the maximum value for a specific property from a list using LINQ

  27. 27

    python更新csv文件,条件为column2从column1开始

  28. 28

    在python中使用enumerate()时从列表中删除元素

  29. 29

    使用python中的enumerate()访问列表中的“操作”对象

热门标签

归档