I am trying to assign values to some rows using pandas dataframe. Is there any function to do this?
问问题
1829 次
2 回答
1
对于一整列:
df = df.assign(column=value)
...column
列的名称在哪里。
对于特定行的特定列:
df.at[row, column] = value
...其中row
是行的索引,是列column
的名称。
后者“就地”更改了数据框。
于 2019-03-28T17:23:19.493 回答
0
这里有一个很好的教程。
基本上,试试这个:
import pandas as pd
import numpy as np
# Creating a dataframe
# Setting the seed value to re-generate the result.
np.random.seed(25)
df = pd.DataFrame(np.random.rand(10, 3), columns =['A', 'B', 'C'])
# np.random.rand(10, 3) has generated a
# random 2-Dimensional array of shape 10 * 3
# which is then converted to a dataframe
df
你会得到这样的东西:
于 2019-03-28T17:22:08.520 回答