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

后端 未结 13 1837
暖寄归人
暖寄归人 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:37

    Let's say that you want to load a 20% sample of the dataset:

        import pandas as pd
        df = pd.read_csv(filepath).sample(frac = 0.20)
    
    0 讨论(0)
提交回复
热议问题