Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/340.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_Dataframe - Fatal编程技术网

Python 如何读取数据帧中的特定单元格并将其写入

Python 如何读取数据帧中的特定单元格并将其写入,python,pandas,dataframe,Python,Pandas,Dataframe,我有以下数据帧: df: 00 01 02 03 04 05 06 07 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 3 0 0 0 0 0 0 0 0 4 0 0 0 0 0 0 0 0 5 0 0 0 0 0 0 0 0

我有以下数据帧:

df:
   00  01  02  03  04  05  06  07
0   0   0   0   0   0   0   0   0
1   0   0   0   0   0   0   0   0
2   0   0   0   0   0   0   0   0
3   0   0   0   0   0   0   0   0
4   0   0   0   0   0   0   0   0
5   0   0   0   0   0   0   0   0
6   0   0   0   0   0   0   0   0
7   0   0   0   0   0   0   0   0
我还有很多INT对,它们表示这个DF中的特定行和列

例如:

3,5---
6,2---
3,1--- 
2,3---
3,1---
应在数据帧中计算匹配数,因此读取所有对后,DF应如下所示:

df:
   00  01  02  03  04  05  06  07
0   0   0   0   0   0   0   0   0
1   0   0   0   2   0   0   0   0
2   0   0   0   0   0   0   1   0
3   0   0   1   0   0   0   0   0
4   0   0   0   0   0   0   0   0
5   0   0   0   1   0   0   0   0
6   0   0   0   0   0   0   0   0
7   0   0   0   0   0   0   0   0

你知道怎么做吗

首先,索引方式是向后的,您需要
然后

用于循环
使用
iloc

pairs = [(5, 3), (2, 6), (1, 3), (3, 2), (1, 3)]

for pair in pairs:
    df.iloc[pair] += 1

# Result

   00  01  02  03  04  05  06  07
0   0   0   0   0   0   0   0   0
1   0   0   0   2   0   0   0   0
2   0   0   0   0   0   0   1   0
3   0   0   1   0   0   0   0   0
4   0   0   0   0   0   0   0   0
5   0   0   0   1   0   0   0   0
6   0   0   0   0   0   0   0   0
7   0   0   0   0   0   0   0   0