简体   繁体   English

从 DataFrame 创建矩阵

[英]Create Matrix from a DataFrame

I have a dataframe with several columns, including Department and ICA.我有一个包含多个列的数据框,包括 Department 和 ICA。 I need to create a matrix where the rows are the departments, and the columns are ICA values (they range from bad-acceptable-good).我需要创建一个矩阵,其中行是部门,列是 ICA 值(它们的范围从坏-可接受-好)。

So position r,c would be a number that shows how many observations of ICA were recorded for each department.所以位置 r,c 将是一个数字,显示每个部门记录了多少 ICA 观察结果。 For example, if Amazonas is row 1 and Acceptable is column 3, position (1,3) would be the number of acceptable observations for Amazonas.例如,如果 Amazonas 是第 1 行,Acceptable 是第 3 列,则位置 (1,3) 将是 Amazonas 的可接受观察数。

Thanks!谢谢!

You can get values from your DataFrame using integer-based indexing with the DataFrame.iloc method.您可以通过DataFrame.iloc方法使用基于整数的索引从 DataFrame 中获取值。 This seems to do what you need.这似乎可以满足您的需求。

For example, if df is your DataFrame, then df.iloc[0, 2] will give you the value at the first row and third column.例如,如果df是您的 DataFrame,则df.iloc[0, 2]将为您提供第一行和第三列的值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM