Read a small random sample from a big CSV file into a Python data frame

后端 未结 13 2018
暖寄归人
暖寄归人 2020-11-27 02:37

The CSV file that I want to read does not fit into main memory. How can I read a few (~10K) random lines of it and do some simple statistics on the selected data frame?

13条回答
  •  孤街浪徒
    2020-11-27 03:16

    For example, you have the loan.csv, you can use this script to easily load the specified number of random items.

    data = pd.read_csv('loan.csv').sample(10000, random_state=44)
    

提交回复
热议问题