Home > other >  Convert numpy array from space separated to comma separated in python
Convert numpy array from space separated to comma separated in python

Time:01-08

This is data in .csv format file generally we expect array/ list with [1,2,3,4] comma separated values which it seems that nothing happened in this case

data = pd.read_csv('file.csv')
data_array = data.values

print(data_array)

print(type(data_array[0]))

and here is the output data

[16025788 179 '179batch1640694482' 18055630 8317948789 '2021-12-28'
 8315780000.0 '6214' 'CA' Nan Nan 'Wireless' '2021-12-28 12:32:46'
 '2021-12-28 12:32:46']

<class 'numpy.ndarray'>

So, i am looking for way to find array with comma separated values

CodePudding user response:

Okay so simply make the changes:

converted_str = numpy.array_str(data_array)
converted_str.replace(' ',',')
print(converted_str)

Now, if you want to get the output in <class 'numpy.ndarray'> simply convert it back to a numpy array. I hope this helps!

  •  Tags:  
  • Related