Get the name of a pandas DataFrame

前端 未结 5 454
灰色年华
灰色年华 2020-11-27 06:48

How do I get the name of a DataFrame and print it as a string?

Example:

boston (var name assigned to a csv file)

import pandas         


        
5条回答
  •  有刺的猬
    2020-11-27 06:59

    In many situations, a custom attribute attached to a pd.DataFrame object is not necessary. In addition, note that pandas-object attributes may not serialize. So pickling will lose this data.

    Instead, consider creating a dictionary with appropriately named keys and access the dataframe via dfs['some_label'].

    df = pd.DataFrame()
    
    dfs = {'some_label': df}
    

提交回复
热议问题