<jupyter_start><jupyter_text>Intro Full path and name of the CSV file is stored in `xample_file`:<jupyter_code>xample_file = 'test.csv'<jupyter_output><empty_output><jupyter_text>Pandas - read_csv()<jupyter_code>import pandas as pd

whole_file = pd.read_csv(xample_file,
                         header=None,
                         #names=['col1', 'col2'] # column names
                        )

print("\n Whole file: \n", whole_file)<jupyter_output>Whole file: 
               0      1
0         Hello  world
1  Hello, world      !
2        What's    up?<jupyter_text>csv.reader()<jupyter_code>import csv

with open(xample_file, 'r') as input_file:
    
    whole_file = []
    
    for obs, row in enumerate( csv.reader(input_file,
                                          delimiter  = ',',
                                          quotechar  = '"',
                                          quoting    = csv.QUOTE_ALL,
                                          skipinitialspace = True,
                                          escapechar = '\\'
                                         )
                             ):
        
        # display row
        print("obs {}: {}".format(obs, row))
        
        # display each column
        for column_n, column in enumerate(row):
            print("> column {}: {}".format(column_n, column))

        # add row to 'whole_file'
        whole_file.append(row)

        
print("\n Whole file: \n", whole_file)<jupyter_output>obs 0: ['Hello', 'world']
> column 0: Hello
> column 1: world
obs 1: ['Hello, world', '!']
> column 0: Hello, world
> column 1: !
obs 2: ["What's", 'up?']
> column 0: What's
> column 1: up?

 Whole file: 
 [['Hello', 'world'], ['Hello, world', '!'], ["What's", 'up?']]<jupyter_text>split(',') each line In the following solution, 'strip()' interprets all commas as delimiters - even those enclosed in quotes. Thus, 3 columns are identified in 2nd row.<jupyter_code>with open(xample_file, 'r') as input_file:
    
    whole_file = []
    
    for obs, row_str in enumerate(input_file, 1):
        
        # represent row as a list
        row_list = row_str.strip().split(',')
        
        # display row
        print("obs {}: {}".format(obs, row_list))
        
        # display each column
        for column_n, column in enumerate(row_list, 1):
            print("> column {}: {}".format(column_n, column))
        
        # add row to 'whole_file'
        whole_file.append(row_list)


print("\n Whole file: \n", whole_file)<jupyter_output>obs 1: ['Hello', 'world']
> column 1: Hello
> column 2: world
obs 2: ['"Hello', ' world"', '!']
> column 1: "Hello
> column 2:  world"
> column 3: !
obs 3: ['"What\'s"', 'up?']
> column 1: "What's"
> column 2: up?

 Whole file: 
 [['Hello', 'world'], ['"Hello', ' world"', '!'], ['"What\'s"', 'up?']]
{'fraction_non_alphanumeric': 0.14426807760141094, 'fraction_numerical': 0.010582010582010581, 'mean_word_length': 1.9146968139773894, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 11, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '288055', 'license': 'MIT', 'n_tokens_mistral': 935, 'n_tokens_neox': 867, 'n_words': 236, 'path': 'Python-techniques/ReadCSV_Basics.ipynb', 'repo_name': 'j-honnacker/data-mgmt-Python', 'size': '2835'}