Read specific columns with pandas or other python module

前端 未结 3 399
囚心锁ツ
囚心锁ツ 2020-11-29 20:25

I have a csv file from this webpage. I want to read some of the columns in the downloaded file (the csv version can be downloaded in the upper right corner).

Let\'s

3条回答
  •  一向
    一向 (楼主)
    2020-11-29 20:56

    According to the latest pandas documentation you can read a csv file selecting only the columns which you want to read.

    import pandas as pd
    
    df = pd.read_csv('some_data.csv', usecols = ['col1','col2'], low_memory = False)
    

    Here we use usecols which reads only selected columns in a dataframe.

    We are using low_memory so that we Internally process the file in chunks.

提交回复
热议问题