Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.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 使用dataframe中的分类数据重命名变量_Python_Pandas_Numpy - Fatal编程技术网

Python 使用dataframe中的分类数据重命名变量

Python 使用dataframe中的分类数据重命名变量,python,pandas,numpy,Python,Pandas,Numpy,我想知道如何在一个包含更多列的熊猫数据框中重命名观测值, 例如: User Age Value Smoke? .... 21 18 0.5 1 212 30 0.2 1 211 32 0.7 0 214 64 0.2 1 212 30 0.2 1 对于一列,我发现这段代码 pd.cut(df['Age'], bins=[-np.inf, 30, np.inf], labels=['<30', '>=30']) 您是否尝

我想知道如何在一个包含更多列的熊猫数据框中重命名观测值, 例如:

User Age Value Smoke? ....
21   18   0.5    1
212  30   0.2    1
211  32   0.7    0
214  64   0.2    1
212  30   0.2    1
对于一列,我发现这段代码

pd.cut(df['Age'], bins=[-np.inf, 30, np.inf], labels=['<30', '>=30'])

您是否尝试将年龄列指定给pd.cut?像这样:

df['Age'] = pd.cut(df['Age'], bins=[-np.inf, 30, np.inf], labels=['<30', '>=30'])
df['Age'] = pd.cut(df['Age'], bins=[-np.inf, 30, np.inf], labels=['<30', '>=30'])
df.drop_duplicates()