1

In Panda DataFrames in python, replacing values by column and index is very straight-forward.

Example DataFrame:

df = pd.DataFrame({'A': [1, 2, 3], 'B': [200, 300, 400]})
   A    B
0  1   200
1  2   300
2  3   400

Replacing values is as simple as:

df['A'][0] = 800
   A     B
0  800  200
1  2    300
2  3    400

How do you replace value by column and index in a Danfo DataFrame ?

2 Answers2

0

Please try:

let df_rep = df.replace({ "replace": 1, "with": 800, "in": ["A"] })

You probably noticed, but just in case, 1 here is the value not the index.

Official documentation

{replace: int, float, str. The value to replace. with: Int, float, str. The new value to replace with. in: Array. An array of column names to replace, If not specified, replace all columns. }

https://danfo.jsdata.org/api-reference/dataframe/danfo.dataframe.replace

Alexandre Jean
  • 622
  • 2
  • 11
  • 19
-1

This feature has not been implemented yet.

You must recreate the DataFrame each time you want to replace a value by column and index.

One easy way is by using display values indices :

df.values[2][3] = 999
df = new dfd.DataFrame(df.values, {index: df.index, columns: df.columns})