简体   繁体   中英

Create Matrix from a DataFrame

I have a dataframe with several columns, including Department and 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).

So position r,c would be a number that shows how many observations of ICA were recorded for each department. For example, if Amazonas is row 1 and Acceptable is column 3, position (1,3) would be the number of acceptable observations for Amazonas.

Thanks!

You can get values from your DataFrame using integer-based indexing with the DataFrame.iloc method. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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