SoFunction
Updated on 2025-03-01

Pandas extracts the value of a cell

If you extract the value of row 1 and column 2:

[[0],[1]]

Then a df will be returned, that is, the field name and line number.

If you use the values ​​attribute to get the value:

[[0],[1]].values

The returned value will be a list, and a nested list:

[[value]]

Therefore, the correct way to write it is:

[[0],[1]].values[0][0]

Supplement: pandas takes out the value of a cell that meets the criteria

The value in the excel table has been read and DATAFRAME----data1

Want to take out some values ​​and write them to another excel table

I found that using data1['Task indicator total profit'][data1['Enterprise']==namelist], assigning values ​​to cells in the excel table, but failed

It is said to be a series, and cannot be written. It can only be written in the way of values[0]

(row=index+5,column=21,value=data1['Total Profit of Task Indicator'][data1['enterprise']==namelist].values[0])
(row=index+5,column=22,value=data1['Task indicators three fees'][data1['enterprise']==namelist].values[0])

I checked some web pages and found:

dataframe[b][dataframe[a]==1].values[0]
dataframe[dataframe[a]==1][b].values[0] #The result is the same,But the process is different

But there is no easier way to write.

The above is personal experience. I hope you can give you a reference and I hope you can support me more. If there are any mistakes or no complete considerations, I would like to give you advice.