Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/312.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从Python访问数据_Python_Pandas - Fatal编程技术网

从Python访问数据

从Python访问数据,python,pandas,Python,Pandas,下面是一个基本的作业问题 创建一个名为heights_a的系列,其值为176.2158.4167.6, 156.2和161.4。这些值代表A班5名学生的身高 将每个学生标记为s1、s2、s3、s4和s5 创建另一个名为weights_A的系列,其值为85.1、90.2、76.8, 80.4和78.9。这些值代表A班5名学生的权重 将每个学生标记为s1、s2、s3、s4和s5 创建一个名为df_a的数据框,其中包含 五名学生中一、中二、中三、中四和中五 分别将列标记为Student_height和

下面是一个基本的作业问题

创建一个名为heights_a的系列,其值为176.2158.4167.6, 156.2和161.4。这些值代表A班5名学生的身高

将每个学生标记为s1、s2、s3、s4和s5

创建另一个名为weights_A的系列,其值为85.1、90.2、76.8, 80.4和78.9。这些值代表A班5名学生的权重

将每个学生标记为s1、s2、s3、s4和s5

创建一个名为df_a的数据框,其中包含 五名学生中一、中二、中三、中四和中五

分别将列标记为Student_height和Student_weight

选择有关学生身高的df_A列,并将其存储在中 高度可变。注意:请在内部指定所需的列名 方括号

打印可变高度的对象类型

到目前为止,已尝试使用以下代码,但检查人员似乎认为高度数据类型不正确。 不确定这在哪里是不正确的

import pandas as pd
import numpy as np



heights_A =  pd.Series([176.2, 158.4, 167.6, 156.2, 161.4])

heights_A.index = ['s1', 's2', 's3', 's4','s5']


weights_A = pd.Series([85.1, 90.2, 76.8, 80.4 , 78.9])

weights_A.index = ['s1', 's2', 's3', 's4','s5']



df_A = pd.DataFrame()

df_A['Student_height'] = heights_A

df_A['Student_weight'] = weights_A

height = df_A[['Student_height']]
height.dtypes
不确定此高度数据类型零件有何错误,请尝试:

height = df_A['Student_height']
height.dtypes

当您使用双方括号时,heights变量是df,当您仅使用单方括号时,将返回一个序列。似乎您的问题需要返回一个系列。

似乎问题只与height=df_a['Student_height']]height.d类型部分w.r.t赋值和数据类型有关。这里面有什么遗漏吗?你能发布准确的错误信息吗?