Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

print dataframe name python

import pandas as pd
# Dataframe example
dfA = pd.DataFrame({'col_A':[1,5,7,8],'col_B':[9,7,4,3], 'col_C':[5,1,4,9]})
dfC= pd.DataFrame({'col_A':[3,5,9,8],'col_B':[1,3,3,6], 'col_C':[9,9,1,6]})

# Dataframe list example
df = [dfA,dfC]

# Get the dataframe name (function)

def get_df_name(data):    
    
    if isinstance(data, list): # To get names from list of dataframes
        name = []
        for d in data:
            n = [x for x in globals() if globals()[x] is d][0]
            name.append(n)
        return name    
    else: # To get name from single dataframe
        name =[x for x in globals() if globals()[x] is data][0]
        return name

# Get the names
dfA_name = get_df_name(dfA)
df_List_name = get_df_name(df)

print(f'Single dataframe name: {dfA_name}')
print(f'Names from list of dataframesdf_List_name: {df_List_name[0]} and {df_List_name[1]}')
Comment

PREVIOUS NEXT
Code Example
Python :: create dictionary python having hash value 
Python :: text to speech program in python 
Python :: camel case to snake case python 
Python :: Python program to calculate area of a rectangle using function 
Python :: create a range of numbers in python 
Python :: car python program 
Python :: Python - How To Convert Bytearray to String 
Python :: python inherit from objects 
Python :: how to duplicate a row in python 
Python :: wisdom 
Python :: how to find last element in array python 
Python :: add dataframe column to set 
Python :: numpy arange number of elements 
Python :: calculator python tutorial 
Python :: python script to read qr code 
Python :: opencv python rgb to hsv 
Python :: how to slice string in python 
Python :: pyqt5 buttons 
Python :: do i need do some set when i use GPU to train tensorflow model 
Python :: python variable definieren 
Python :: decoding 
Python :: how to flatten list of lists in python 
Python :: pythagore 
Python :: geometric progression in python 
Python :: code optimization in python 
Python :: how to add to end of linked list python 
Python :: Math Module radians() Function in python 
Python :: discord.py 8ball 
Python :: how to get github repository access in python code directly 
Python :: python while loop and recursion 
ADD CONTENT
Topic
Content
Source link
Name
9+4 =