获取 Pandas DataFrame 的名称 [英] Get the name of a pandas DataFrame

查看:34
本文介绍了获取 Pandas DataFrame 的名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取 DataFrame 的名称并将其打印为字符串?

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

示例:

boston(分配给 csv 文件的变量名)

boston (var name assigned to a csv file)

import pandas as pd
boston = pd.read_csv('boston.csv')

print('The winner is team A based on the %s table.) % boston

推荐答案

您可以使用以下内容命名数据框,然后随意调用该名称:

You can name the dataframe with the following, and then call the name wherever you like:

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

print df.name
>>>
Ones

希望有所帮助.

这篇关于获取 Pandas DataFrame 的名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆