How to transfer an str Series into a two dimensional ndarray? [closed]
enter image description here
this is my data
and I wanna transfer it into a two dimensional ndarray, I have tried many methods, like np.from_string, pd.pd.to_numeric, but I can't solve it
thanks in advanced.
python-3.x pandas numpy
closed as unclear what you're asking by Vega, AdrianHHH, Gert Arnold, sideshowbarker, Makyen Nov 24 '18 at 21:59
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |
enter image description here
this is my data
and I wanna transfer it into a two dimensional ndarray, I have tried many methods, like np.from_string, pd.pd.to_numeric, but I can't solve it
thanks in advanced.
python-3.x pandas numpy
closed as unclear what you're asking by Vega, AdrianHHH, Gert Arnold, sideshowbarker, Makyen Nov 24 '18 at 21:59
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
Please add code, errors and data as text (using code formatting), not images. Images: A) don't allow us to copy-&-paste the code/errors/data for testing; B) don't permit searching based on the code/error/data contents; and many more reasons. In general, code/errors/data in text format >>>> code/errors/data as an image >> nothing. Images should only be used, in addition to text in code format, if having the image adds something significant that is not conveyed by just the text code/error/data.
– Makyen
Nov 24 '18 at 22:00
add a comment |
enter image description here
this is my data
and I wanna transfer it into a two dimensional ndarray, I have tried many methods, like np.from_string, pd.pd.to_numeric, but I can't solve it
thanks in advanced.
python-3.x pandas numpy
enter image description here
this is my data
and I wanna transfer it into a two dimensional ndarray, I have tried many methods, like np.from_string, pd.pd.to_numeric, but I can't solve it
thanks in advanced.
python-3.x pandas numpy
python-3.x pandas numpy
asked Nov 24 '18 at 7:05
duckluducklu
63
63
closed as unclear what you're asking by Vega, AdrianHHH, Gert Arnold, sideshowbarker, Makyen Nov 24 '18 at 21:59
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
closed as unclear what you're asking by Vega, AdrianHHH, Gert Arnold, sideshowbarker, Makyen Nov 24 '18 at 21:59
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
Please add code, errors and data as text (using code formatting), not images. Images: A) don't allow us to copy-&-paste the code/errors/data for testing; B) don't permit searching based on the code/error/data contents; and many more reasons. In general, code/errors/data in text format >>>> code/errors/data as an image >> nothing. Images should only be used, in addition to text in code format, if having the image adds something significant that is not conveyed by just the text code/error/data.
– Makyen
Nov 24 '18 at 22:00
add a comment |
Please add code, errors and data as text (using code formatting), not images. Images: A) don't allow us to copy-&-paste the code/errors/data for testing; B) don't permit searching based on the code/error/data contents; and many more reasons. In general, code/errors/data in text format >>>> code/errors/data as an image >> nothing. Images should only be used, in addition to text in code format, if having the image adds something significant that is not conveyed by just the text code/error/data.
– Makyen
Nov 24 '18 at 22:00
Please add code, errors and data as text (using code formatting), not images. Images: A) don't allow us to copy-&-paste the code/errors/data for testing; B) don't permit searching based on the code/error/data contents; and many more reasons. In general, code/errors/data in text format >>>> code/errors/data as an image >> nothing. Images should only be used, in addition to text in code format, if having the image adds something significant that is not conveyed by just the text code/error/data.
– Makyen
Nov 24 '18 at 22:00
Please add code, errors and data as text (using code formatting), not images. Images: A) don't allow us to copy-&-paste the code/errors/data for testing; B) don't permit searching based on the code/error/data contents; and many more reasons. In general, code/errors/data in text format >>>> code/errors/data as an image >> nothing. Images should only be used, in addition to text in code format, if having the image adds something significant that is not conveyed by just the text code/error/data.
– Makyen
Nov 24 '18 at 22:00
add a comment |
1 Answer
1
active
oldest
votes
Use list comprehension
with split
and converting to np.array
:
df = pd.DataFrame({'pixels':['70 80 82 72','151 1050 147 155']})
print (df)
pixels
0 70 80 82 72
1 151 1050 147 155
arr = np.array([x.split() for x in df['pixels']]).astype(int)
print (arr)
[[ 70 80 82 72]
[ 151 1050 147 155]]
If data in file:
arr = np.genfromtxt('my_file.csv', delimiter=' ', dtype=np.int64)
print(arr)
[[ 70 80 82 72]
[ 151 1050 147 155]]
@ducklu - How was createdDataFrame
?
– jezrael
Nov 24 '18 at 7:13
I download the data in an image database for the emotion recognition
– ducklu
Nov 24 '18 at 7:17
@ducklu - link is possible see?
– jezrael
Nov 24 '18 at 7:18
it's fer_2013 from Kaggle, but I forget the link, sorry
– ducklu
Nov 24 '18 at 7:21
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Use list comprehension
with split
and converting to np.array
:
df = pd.DataFrame({'pixels':['70 80 82 72','151 1050 147 155']})
print (df)
pixels
0 70 80 82 72
1 151 1050 147 155
arr = np.array([x.split() for x in df['pixels']]).astype(int)
print (arr)
[[ 70 80 82 72]
[ 151 1050 147 155]]
If data in file:
arr = np.genfromtxt('my_file.csv', delimiter=' ', dtype=np.int64)
print(arr)
[[ 70 80 82 72]
[ 151 1050 147 155]]
@ducklu - How was createdDataFrame
?
– jezrael
Nov 24 '18 at 7:13
I download the data in an image database for the emotion recognition
– ducklu
Nov 24 '18 at 7:17
@ducklu - link is possible see?
– jezrael
Nov 24 '18 at 7:18
it's fer_2013 from Kaggle, but I forget the link, sorry
– ducklu
Nov 24 '18 at 7:21
add a comment |
Use list comprehension
with split
and converting to np.array
:
df = pd.DataFrame({'pixels':['70 80 82 72','151 1050 147 155']})
print (df)
pixels
0 70 80 82 72
1 151 1050 147 155
arr = np.array([x.split() for x in df['pixels']]).astype(int)
print (arr)
[[ 70 80 82 72]
[ 151 1050 147 155]]
If data in file:
arr = np.genfromtxt('my_file.csv', delimiter=' ', dtype=np.int64)
print(arr)
[[ 70 80 82 72]
[ 151 1050 147 155]]
@ducklu - How was createdDataFrame
?
– jezrael
Nov 24 '18 at 7:13
I download the data in an image database for the emotion recognition
– ducklu
Nov 24 '18 at 7:17
@ducklu - link is possible see?
– jezrael
Nov 24 '18 at 7:18
it's fer_2013 from Kaggle, but I forget the link, sorry
– ducklu
Nov 24 '18 at 7:21
add a comment |
Use list comprehension
with split
and converting to np.array
:
df = pd.DataFrame({'pixels':['70 80 82 72','151 1050 147 155']})
print (df)
pixels
0 70 80 82 72
1 151 1050 147 155
arr = np.array([x.split() for x in df['pixels']]).astype(int)
print (arr)
[[ 70 80 82 72]
[ 151 1050 147 155]]
If data in file:
arr = np.genfromtxt('my_file.csv', delimiter=' ', dtype=np.int64)
print(arr)
[[ 70 80 82 72]
[ 151 1050 147 155]]
Use list comprehension
with split
and converting to np.array
:
df = pd.DataFrame({'pixels':['70 80 82 72','151 1050 147 155']})
print (df)
pixels
0 70 80 82 72
1 151 1050 147 155
arr = np.array([x.split() for x in df['pixels']]).astype(int)
print (arr)
[[ 70 80 82 72]
[ 151 1050 147 155]]
If data in file:
arr = np.genfromtxt('my_file.csv', delimiter=' ', dtype=np.int64)
print(arr)
[[ 70 80 82 72]
[ 151 1050 147 155]]
edited Nov 24 '18 at 7:20
answered Nov 24 '18 at 7:06
jezraeljezrael
329k23270349
329k23270349
@ducklu - How was createdDataFrame
?
– jezrael
Nov 24 '18 at 7:13
I download the data in an image database for the emotion recognition
– ducklu
Nov 24 '18 at 7:17
@ducklu - link is possible see?
– jezrael
Nov 24 '18 at 7:18
it's fer_2013 from Kaggle, but I forget the link, sorry
– ducklu
Nov 24 '18 at 7:21
add a comment |
@ducklu - How was createdDataFrame
?
– jezrael
Nov 24 '18 at 7:13
I download the data in an image database for the emotion recognition
– ducklu
Nov 24 '18 at 7:17
@ducklu - link is possible see?
– jezrael
Nov 24 '18 at 7:18
it's fer_2013 from Kaggle, but I forget the link, sorry
– ducklu
Nov 24 '18 at 7:21
@ducklu - How was created
DataFrame
?– jezrael
Nov 24 '18 at 7:13
@ducklu - How was created
DataFrame
?– jezrael
Nov 24 '18 at 7:13
I download the data in an image database for the emotion recognition
– ducklu
Nov 24 '18 at 7:17
I download the data in an image database for the emotion recognition
– ducklu
Nov 24 '18 at 7:17
@ducklu - link is possible see?
– jezrael
Nov 24 '18 at 7:18
@ducklu - link is possible see?
– jezrael
Nov 24 '18 at 7:18
it's fer_2013 from Kaggle, but I forget the link, sorry
– ducklu
Nov 24 '18 at 7:21
it's fer_2013 from Kaggle, but I forget the link, sorry
– ducklu
Nov 24 '18 at 7:21
add a comment |
Please add code, errors and data as text (using code formatting), not images. Images: A) don't allow us to copy-&-paste the code/errors/data for testing; B) don't permit searching based on the code/error/data contents; and many more reasons. In general, code/errors/data in text format >>>> code/errors/data as an image >> nothing. Images should only be used, in addition to text in code format, if having the image adds something significant that is not conveyed by just the text code/error/data.
– Makyen
Nov 24 '18 at 22:00