Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/317.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 从字典更改pandas的行值_Python_Python 3.x_Pandas_Dataframe - Fatal编程技术网

Python 从字典更改pandas的行值

Python 从字典更改pandas的行值,python,python-3.x,pandas,dataframe,Python,Python 3.x,Pandas,Dataframe,我有一个数据框,如果它出现在字典中,我需要在其中更改行值,如下所示: dict = {"A":Apple:"B":Ball,"C":Cat} c1 c2 c3 0 A Tree GH 1 B Train GC 2 C Yarn GR 如果存在dict,我希望更改列c1的值 df.c1.map(dict)?或者,df.replace({'c

我有一个数据框,如果它出现在字典中,我需要在其中更改行值,如下所示:

dict = {"A":Apple:"B":Ball,"C":Cat}

        c1          c2      c3
0       A          Tree     GH
1       B          Train    GC
2       C          Yarn     GR

如果存在dict,我希望更改列c1的值

df.c1.map(dict)
?或者,
df.replace({'c1':ddict})
您的dict对于替换无效,您需要使值字符串也带有引号。用法:
dict={“A”:“Apple”,“B”:“Ball”,“C”:“Cat”}