how do i remove ' ' [ ] in array (python)

Viewed 67

i have this code:

dfx = pd.read_csv('hasil_processing_auto.csv', encoding='unicode_escape')
dy = dfx.loc[:,'polarity']
X = dy.values

print(X)

and this is the output i get:

['[0]' '[0]' '[0]' '[0]' '[0]' '[0]' '[0]' '[0]' '[0]' '[0]' '[0]' '[0]'
 '[1]' '[0]' '[0]' '[0]' '[0]' '[0]' '[0]' '[1]']

i want it to be just like [0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1]

the csv is like this:

    tweets                                              label   polarity
0   i love myself kuliah tugas tumpuk sapu ngepel ...   Netral  [0]
1   suogh online online kuliah                          Netral  [0]
2   bisnis sekolah kuliah ngantor online shop prod...   Netral  [0]
3   tunggu surat putus rektor surat putus dekan la...   Netral  [0]
4   kuliah online bosan                                 Netral  [0]
.....
1 Answers

The easiest way is to strip the column as such:

'[0]'[1:-1] --> '0'

If you are new to Python, you can treat a string as an iterable so you can subset it by [start:end]

dfx['polarity'] = dfx['polarity'].apply(lambda x: x[1:-1])
Related