Get the name Pandas DataFrame [Python]

How do I get the name of a DataFrame and print it as a string? Thank you gentlemen!

example:

boston (var name assigned to csv file)

boston = read_csv('boston.csv') print ('The winner is team A based on the %s table.) % boston 
+11
python dataframe
Jul 30 '15 at 15:01
source share
2 answers

You can call the dataframe with the following text and then call the name anywhere:

 import pandas as pd df = pd.DataFrame( data=np.ones([4,4]) ) df.name = 'Ones' print df.name >>> Ones 

Hope this helps.

+13
Jul 30 '15 at 15:09
source share

From here , what I understand is DataFrames:

A DataFrame is a two-dimensional labeled data structure with columns of potentially different types. You can think of it as a table or SQL table, or as a type of Series object.

And series:

A series is a one-dimensional labeled array that can hold any type of data (integers, strings, floating-point numbers, Python objects, etc.).

The series has a name attribute, which can be accessed like this:

  In [27]: s = pd.Series(np.random.randn(5), name='something') In [28]: s Out[28]: 0 0.541 1 -1.175 2 0.129 3 0.043 4 -0.429 Name: something, dtype: float64 In [29]: s.name Out[29]: 'something' 

EDIT: Based on the OP comments, I think the OP was looking for something like:

  >>> df = pd.DataFrame(...) >>> df.name = 'df' # making a custom attribute that DataFrame doesn't intrinsically have >>> print(df.name) 'df' 
+2
Jul 30 '15 at 15:11
source share



All Articles