I have a dataframe name “detalhe” with several columns and one is named: “Concelho”. I have a list of unique values of “Concelho” named “Concelho ADENE” and I would like to replace each occurrence with a different list called “INE”.
JavaScript
x
10
10
1
Concelho ADENE INE
2
0 ABRANTES Abrantes
3
1 AGUEDA Águeda
4
2 AGUIAR DA BEIRA Aguiar da Beira
5
3 ALANDROAL Alandroal
6
4 ALBERGARIA-A-VELHA Albergaria-a-Velha
7
8
284 VIMIOSO Vimioso
9
285 VINHAIS Vinhais
10
Both lists have the same length and each entrance correspond (they are alphanumeric sorted) (I also have a csv file with both lists as 2 parallels columns.)
I tried:
JavaScript
1
6
1
detalhe= pd.read_csv('Detalhe.csv')
2
detalhe['Concelho'].replace(Concelho ADENE,INE)
3
detalhe
4
5
AttributeError: 'Series' object has no attribute '_replace_columnwise'
6
Advertisement
Answer
could you please provide a sample code(like below) to check to reproduce the scenario? replacing using list is working fine
JavaScript
1
11
11
1
df = pd.DataFrame({'A': [0, 1, 2, 3, 4],
2
'B': [5, 6, 7, 8, 9],
3
'C': ['a', 'b', 'c', 'd', 'e']})
4
print(df)
5
print("-----------")
6
7
init = [7,6,9]
8
final = [17,16,19]
9
df.B.replace(init,final,inplace=True)
10
print(df)
11
output:
JavaScript
1
14
14
1
A B C
2
0 0 5 a
3
1 1 6 b
4
2 2 7 c
5
3 3 8 d
6
4 4 9 e
7
-----------
8
A B C
9
0 0 5 a
10
1 1 16 b
11
2 2 17 c
12
3 3 8 d
13
4 4 19 e
14