到目前为止,我正在尝试使用熊猫从数据中提取多个详细信息,但没有成功。我真的很想得到一些帮助,因为我是一个新手程序员。
我有下面的数据框架,我是从excel导入的。我已经包括了一些问题的尝试代码。
该数据框架包括3家制造商、4种产品类型、独特的产品代码以及各自的推出年份。
DATAFRAME
问题和期望的产出:
我想问题是不言而喻的
的产品代码列表
如何为所有包含单词'Construction'的制造商显示产品代码列表
最高和阿尔法包含了结构一词,因此:
(construction) (
这也是不言自明的。所以输出是问题4输出表的平均发射年。
企图编码:
问题1:
x1=df[df.Manufacturer ='Alpha Productions' & df.Product_Code='Metals'].YOB.mean()
print(x1)
问题2:
x2=df[df.Manufacturer =='Alpha Productions' & df.Manufacturer=='Supreme Productions']
print (x2)
问题4:
x4=df[df.Manufacturer==str.contains.Construction]
print(x4)
发布于 2019-10-14 14:33:05
由于您没有提供测试数据集,所以我还没有测试这些数据集:
Q1:
x1=df[(df.Manufacturer=='Alpha Productions') & (df.Product_Code=='Metals')].Launch_Year.mean()
print(x1)
Q2:
x2=df[(df.Manufacturer =='Alpha Productions') | (df.Manufacturer=='Supreme Productions')]
print (x2)
Q3:
mask_manufacturer = (df.Manufacturer=='Alpha') | (df.Manufacturer=='Lamda Productions')
mask_type = (df.Product_Type=='Metals') | (df.Product_Type=='Electronics')
print(df[mask_manufacturer & mask_type]
Q4:
x4=df[df.Manufacturer.str.contains("Construction")].Product_Code
print(x4)
Q5:
x5=df[df.Manufacturer.str.contains("Construction") & df.Product_Type == "Metals"].Launch_Year.mean()
print(x5)
https://stackoverflow.com/questions/58378552
复制相似问题