为什么我们要使用式式键来获取钥匙,而不是获得值
我在此示例中有一个问题:
Country1 = {'Japan': 80, 'China': 450, 'India': 200, 'USA': 250}
Country2 = {'Brazil': 100,'China': 500, 'India': 210,'USA': 260}
# Convert into Pandas Series
sales_Q1 = pd.Series(Country1)
sales_Q2 = pd.Series(Country2)
sales_Q1.keys() #=====> Index(['Japan', 'China', 'India', 'USA'], dtype='object')
sales_Q1.values #=====> array([ 80, 450, 200, 250], dtype=int64)
问题:为什么我们要使用括号来获取钥匙而不获得值?
I have a question in this example:
Country1 = {'Japan': 80, 'China': 450, 'India': 200, 'USA': 250}
Country2 = {'Brazil': 100,'China': 500, 'India': 210,'USA': 260}
# Convert into Pandas Series
sales_Q1 = pd.Series(Country1)
sales_Q2 = pd.Series(Country2)
sales_Q1.keys() #=====> Index(['Japan', 'China', 'India', 'USA'], dtype='object')
sales_Q1.values #=====> array([ 80, 450, 200, 250], dtype=int64)
Question: Why do we use brackets to get keys and not to get values?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
.keys()
称为方法,.values
称为属性。这是一个简单的示例,可以让您了解什么是方法和属性。
因此,要回答您的问题,为什么我们要使用括号来获取键而不是获得值,这是因为
pandas
codebase设计,使用.keys()
作为方法和方法.values
作为属性Using
.keys()
known as a method, and.values
known as an attribute.Here's a simple example to give you clearance about what are method and attributes.
So to answer your question why do we use parentheses to get keys and not to get values, it's because of the
pandas
codebase design, that uses.keys()
as method and.values
as attribute