Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Letter appeared in data when arff loaded into Python

I have loaded an arff file to python using this code:

import pandas as pd, scipy as sp
from scipy.io import arff
datos,meta = arff.loadarff(open('selectividad.arff', 'r'))
d = pd.DataFrame(datos)

When I use head function to see the data frame, this is how it looks: enter image description here

However, those 'b' are not present in the arff file as we can see below: https://gyazo.com/3123aa4c7007cb4d6f99241b1fc41bcb What is the problem here? Thank you very much

like image 205
Javier Lopez Tomas Avatar asked Oct 16 '25 20:10

Javier Lopez Tomas


1 Answers

For one column, apply the following code:

data['name_column'] = data['name_column'].str.decode('utf-8') 

For a dataframe, apply:

str_df = df.select_dtypes([object])
str_df = str_df.stack().str.decode('utf-8').unstack()
like image 117
Renata Galdino Avatar answered Oct 18 '25 16:10

Renata Galdino



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!