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

Python 使用pandas更改数据框的特定列

Python 使用pandas更改数据框的特定列,python,pandas,dataframe,Python,Pandas,Dataframe,我有一个数据框3列:[“date”、“volume”、“ID”]。ID=0,1,2…15。 我想创建新的数据框:保留ID=5的所有行 其他行:仍然保留所有行,但将行[“volume”]=0首先复制数据帧: df_new = df.copy() 然后,根据您的条件,使用将音量设置为0: df_new.loc[df_new['ID'] != 5, 'volume'] = 0

我有一个数据框3列:[“
date
”、“
volume
”、“
ID
”]。ID=0,1,2…15。 我想创建新的数据框:保留ID=5的所有行


其他行:仍然保留所有行,但将
行[“volume”]=0

首先复制数据帧:

df_new = df.copy()
然后,根据您的条件,使用将音量设置为0:

df_new.loc[df_new['ID'] != 5, 'volume'] = 0