How does Python Pandas process a list of tables?
<p>I have this simple clean_data function, which will round the numbers in the input data frame. The code works, but I am very puzzled why it works. Could anybody help me understand?</p>

<p>The part where I got confused is this. table_list is a new list of data frame, so after running the code, each item inside table_list should be formatted, while tablea, tableb, and tablec should stay the same. But apparently I am wrong. After running the code, all three tables are formatted correctly. What is going on? Thanks a lot for the help.</p>

<pre><code>table_list = [tablea, tableb, tablec]

def clean_data(df):

    for i in df:
        df[i] = df[i].map(lambda x: round(x, 4))

    return df

map(clean_data, table_list)
</code></pre>

<p>In Python, a list of dataframes, or any complicated objects, is simply a list of references that will point to the underlying data frames. For example, the first element of table_list is a reference to tablea. Therefore, clean_data will go directly to the data frame, i.e., tablea, following the reference given by table_list[0].</p>

python pandas