Converting strings Series to numeric one
up vote
0
down vote
favorite
I'm doing
X = data['x'].apply(lambda h: [int(h[i:i + 2], 16) for i in (0, 2 ,4)])
Where x
has strings of hex colors, and I'd like to map them to RGB arrays (3 values each). After that, X
hasdtype='object
, and X.values
is a numpy array of numpy arrays.
My final goal is making it an 3 * n
numpy array and use it with sklearn.cluster.KMeans
. What is the best way to achieving this?
pandas
add a comment |
up vote
0
down vote
favorite
I'm doing
X = data['x'].apply(lambda h: [int(h[i:i + 2], 16) for i in (0, 2 ,4)])
Where x
has strings of hex colors, and I'd like to map them to RGB arrays (3 values each). After that, X
hasdtype='object
, and X.values
is a numpy array of numpy arrays.
My final goal is making it an 3 * n
numpy array and use it with sklearn.cluster.KMeans
. What is the best way to achieving this?
pandas
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I'm doing
X = data['x'].apply(lambda h: [int(h[i:i + 2], 16) for i in (0, 2 ,4)])
Where x
has strings of hex colors, and I'd like to map them to RGB arrays (3 values each). After that, X
hasdtype='object
, and X.values
is a numpy array of numpy arrays.
My final goal is making it an 3 * n
numpy array and use it with sklearn.cluster.KMeans
. What is the best way to achieving this?
pandas
I'm doing
X = data['x'].apply(lambda h: [int(h[i:i + 2], 16) for i in (0, 2 ,4)])
Where x
has strings of hex colors, and I'd like to map them to RGB arrays (3 values each). After that, X
hasdtype='object
, and X.values
is a numpy array of numpy arrays.
My final goal is making it an 3 * n
numpy array and use it with sklearn.cluster.KMeans
. What is the best way to achieving this?
pandas
pandas
edited Nov 19 at 14:35
asked Nov 19 at 14:24
galah92
884816
884816
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
After creating X, you can split up the data into 3 columns like this
X = data['x'].apply(lambda h: [int(h[i:i + 2], 16) for i in (0, 2 ,4)])
data[['R','G','B']] = pd.DataFrame(X.values.tolist(), index=X.index)
so that
data[['R','G','B']]
has the result in three columns for further processing
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
After creating X, you can split up the data into 3 columns like this
X = data['x'].apply(lambda h: [int(h[i:i + 2], 16) for i in (0, 2 ,4)])
data[['R','G','B']] = pd.DataFrame(X.values.tolist(), index=X.index)
so that
data[['R','G','B']]
has the result in three columns for further processing
add a comment |
up vote
0
down vote
After creating X, you can split up the data into 3 columns like this
X = data['x'].apply(lambda h: [int(h[i:i + 2], 16) for i in (0, 2 ,4)])
data[['R','G','B']] = pd.DataFrame(X.values.tolist(), index=X.index)
so that
data[['R','G','B']]
has the result in three columns for further processing
add a comment |
up vote
0
down vote
up vote
0
down vote
After creating X, you can split up the data into 3 columns like this
X = data['x'].apply(lambda h: [int(h[i:i + 2], 16) for i in (0, 2 ,4)])
data[['R','G','B']] = pd.DataFrame(X.values.tolist(), index=X.index)
so that
data[['R','G','B']]
has the result in three columns for further processing
After creating X, you can split up the data into 3 columns like this
X = data['x'].apply(lambda h: [int(h[i:i + 2], 16) for i in (0, 2 ,4)])
data[['R','G','B']] = pd.DataFrame(X.values.tolist(), index=X.index)
so that
data[['R','G','B']]
has the result in three columns for further processing
answered Nov 19 at 15:14
576i
2,1831033
2,1831033
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53376676%2fconverting-strings-series-to-numeric-one%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown