I extracted the value from csv with Python, and when I tried to turn it with the for statement, the extracted data was ** ndarray **, which was a version of the array without commas (,), so I had a hard time. => I solved it, so make a note
** Extraction destination csv **
sample.csv
sample_name,sample_colomn
aaaaaaaaaaa,bbbbbbbbbbbbb
ccccccccccc,ddddddddddddd
** Logic for extraction **
sample.py
import pandas as pd
import numpy as np
sample_data = pd.read_csv('sample.csv',index_col='sample_colomn')
sample_colomn = sample_data.index.values
print(sample_colomn)
# ['bbbbbbbbbbbbb' 'ddddddddddddd']
When I tried to turn ['bbbbbbbbbbbbb''ddddddddddddd']
with a for statement, I got angry with Type Error: only integer scalar arrays can be converted to a scalar index
.
Use ** tolist () ** to convert a version of an array without a comma (,) to a regular array (list)
sample.py
import pandas as pd
import numpy as np
sample_data = pd.read_csv('sample.csv',index_col='sample_colomn')
sample_colomn = sample_data.index.values
print(sample_colomn.tolist())
# ['bbbbbbbbbbbbb', 'ddddddddddddd']
that's all!
reference https://note.nkmk.me/python-numpy-list/
Recommended Posts