<jupyter_start><jupyter_text>Importing flat files Flat files are an important part of the data analysis and data science workflow and a common way to both store and transfer data between people and systems. The most common format that I've come across is the `.csv` format which can be easily handled using the `pandas` library.<jupyter_code>import pandas as pd # Import pandas

path_to_file = '../data/craft-cans/beers.csv'
beers = pd.read_csv(path_to_file)<jupyter_output><empty_output><jupyter_text>At its most basic level, that is it. We now have access to the information that is stored in the `beers.csv` csv file in the data section of this repository.<jupyter_code>beers.head()
beers.describe()<jupyter_output><empty_output><jupyter_text>Having had more of a look, we can see that the first column (`Unnamed: 0`) most likely just represents a primary index for the beers table. We could either remove it, or we could specify that when we load the data in the first place.<jupyter_code>beers2 = pd.read_csv(path_to_file, index_col=0)
beers2.head()<jupyter_output><empty_output><jupyter_text>In the above instance, I specified that I wanted the first column to become the index of the DataFrame using the index of the column: `0` = first column.  Let's say, for instance, that we wanted the name column to be the index column when we loaded the data in. We could specify it by the name of the column, rather than the index, as shown below.<jupyter_code>beers3 = pd.read_csv(path_to_file, index_col='name')
beers3.head()<jupyter_output><empty_output><jupyter_text>As a side note, we could have simply reindexed `beers2` to achieve effectively the same result without having to reload the data.<jupyter_code>beers2.set_index('name').head()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.07388606880992668, 'fraction_numerical': 0.005076142131979695, 'mean_word_length': 5.745247148288973, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '228113', 'license': 'MIT', 'n_tokens_mistral': 542, 'n_tokens_neox': 526, 'n_words': 227, 'path': 'importing_data/flat_files.ipynb', 'repo_name': 'willcanniford/python-learning', 'size': '1773'}