How to convert value's in DF by loop?How to merge two dictionaries in a single expression?How do I check if a list is empty?How do I check whether a file exists without exceptions?How can I safely create a nested directory?Converting string into datetimeAccessing the index in 'for' loops?Convert bytes to a string?How do I sort a dictionary by value?How do I list all files of a directory?Iterating over dictionaries using 'for' loops
Could a 19.25mm revolver actually exist?
First Match - awk
A steel cutting sword?
Convert Byte array into collection of items of different types
Compaq Portable vs IBM 5155 Portable PC
Need to read my home electrical meter
Does COBRA make sense anymore with the ACA?
Why most published works in medical imaging try reducing false positives?
Is it possible to remotely hack the GPS system and disable GPS service worldwide?
Python program to take in two strings and print the larger string
Dad jokes are fun
How to respond to upset student?
Where's this lookout in Nova Scotia?
Why were helmets and other body armour not commonplace in the 1800s?
Apt - strange requests to d16r8ew072anqo.cloudfront.net:80
How should I introduce map drawing to my players?
Should one buy new hardware after a system compromise?
Count Even Digits In Number
Did 20% of US soldiers in Vietnam use heroin, 95% of whom quit afterwards?
Question in discrete mathematics about group permutations
Find the three digit Prime number P from the given unusual relationships
Is it rude to call a professor by their last name with no prefix in a non-academic setting?
Is the field of q-series 'dead'?
I know that there is a preselected candidate for a position to be filled at my department. What should I do?
How to convert value's in DF by loop?
How to merge two dictionaries in a single expression?How do I check if a list is empty?How do I check whether a file exists without exceptions?How can I safely create a nested directory?Converting string into datetimeAccessing the index in 'for' loops?Convert bytes to a string?How do I sort a dictionary by value?How do I list all files of a directory?Iterating over dictionaries using 'for' loops
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I have data set with string column and I had to convert them into int value the problem is some columns have 90+ different value and to convert them
manually and take time, there is a function to solve it automatically?
I did it, but manually:
price_dict = 91:0, 65:1, 0:1, 20:1, 35:1, 32:1, 41:1, 36:1, 15:1, 90:1, 6:1, 67:1, 2:1, 57:1, 39:1, 1:1, 79:1, 34:1, 85:1 # not all
app[`Price`] = app[`Price`].apply(lambda a: price_dict[a]) # 0 = free, 1 = not free
app[`Price`].value_counts() # To check.
I have tried :
for x in app[`Price`]:
if x == 1:
price_dict = 91:0
else:
price_dict = x:1
app[`Price`] = app[`Price`].apply(lambda a: price_dict[a])# 0 = free, 1 = not free
app[`Price`].value_counts()
python
add a comment |
I have data set with string column and I had to convert them into int value the problem is some columns have 90+ different value and to convert them
manually and take time, there is a function to solve it automatically?
I did it, but manually:
price_dict = 91:0, 65:1, 0:1, 20:1, 35:1, 32:1, 41:1, 36:1, 15:1, 90:1, 6:1, 67:1, 2:1, 57:1, 39:1, 1:1, 79:1, 34:1, 85:1 # not all
app[`Price`] = app[`Price`].apply(lambda a: price_dict[a]) # 0 = free, 1 = not free
app[`Price`].value_counts() # To check.
I have tried :
for x in app[`Price`]:
if x == 1:
price_dict = 91:0
else:
price_dict = x:1
app[`Price`] = app[`Price`].apply(lambda a: price_dict[a])# 0 = free, 1 = not free
app[`Price`].value_counts()
python
add a comment |
I have data set with string column and I had to convert them into int value the problem is some columns have 90+ different value and to convert them
manually and take time, there is a function to solve it automatically?
I did it, but manually:
price_dict = 91:0, 65:1, 0:1, 20:1, 35:1, 32:1, 41:1, 36:1, 15:1, 90:1, 6:1, 67:1, 2:1, 57:1, 39:1, 1:1, 79:1, 34:1, 85:1 # not all
app[`Price`] = app[`Price`].apply(lambda a: price_dict[a]) # 0 = free, 1 = not free
app[`Price`].value_counts() # To check.
I have tried :
for x in app[`Price`]:
if x == 1:
price_dict = 91:0
else:
price_dict = x:1
app[`Price`] = app[`Price`].apply(lambda a: price_dict[a])# 0 = free, 1 = not free
app[`Price`].value_counts()
python
I have data set with string column and I had to convert them into int value the problem is some columns have 90+ different value and to convert them
manually and take time, there is a function to solve it automatically?
I did it, but manually:
price_dict = 91:0, 65:1, 0:1, 20:1, 35:1, 32:1, 41:1, 36:1, 15:1, 90:1, 6:1, 67:1, 2:1, 57:1, 39:1, 1:1, 79:1, 34:1, 85:1 # not all
app[`Price`] = app[`Price`].apply(lambda a: price_dict[a]) # 0 = free, 1 = not free
app[`Price`].value_counts() # To check.
I have tried :
for x in app[`Price`]:
if x == 1:
price_dict = 91:0
else:
price_dict = x:1
app[`Price`] = app[`Price`].apply(lambda a: price_dict[a])# 0 = free, 1 = not free
app[`Price`].value_counts()
python
python
edited Mar 24 at 5:11
Miroslav Glamuzina
2,85721223
2,85721223
asked Mar 24 at 2:31
mim alamlkimim alamlki
31
31
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
You can use map
to transform a column using a dictionary to define the transformation:
price_dict = 91:0, 65:1, 0:1, 20:1, 35:1, 32:1, 41:1, 36:1, 15:1, 90:1, 6:1, 67:1, 2:1, 57:1, 39:1, 1:1, 79:1, 34:1, 85:1 # not all
app['Price'] = app['Price'].map(price_dict)
app['Price'].value_counts()
You can also replace values in columns like this:
app['Price_new'] = 1
app.loc[app.Price == 91, 'Price_new'] = 0
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
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%2f55320244%2fhow-to-convert-values-in-df-by-loop%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can use map
to transform a column using a dictionary to define the transformation:
price_dict = 91:0, 65:1, 0:1, 20:1, 35:1, 32:1, 41:1, 36:1, 15:1, 90:1, 6:1, 67:1, 2:1, 57:1, 39:1, 1:1, 79:1, 34:1, 85:1 # not all
app['Price'] = app['Price'].map(price_dict)
app['Price'].value_counts()
You can also replace values in columns like this:
app['Price_new'] = 1
app.loc[app.Price == 91, 'Price_new'] = 0
add a comment |
You can use map
to transform a column using a dictionary to define the transformation:
price_dict = 91:0, 65:1, 0:1, 20:1, 35:1, 32:1, 41:1, 36:1, 15:1, 90:1, 6:1, 67:1, 2:1, 57:1, 39:1, 1:1, 79:1, 34:1, 85:1 # not all
app['Price'] = app['Price'].map(price_dict)
app['Price'].value_counts()
You can also replace values in columns like this:
app['Price_new'] = 1
app.loc[app.Price == 91, 'Price_new'] = 0
add a comment |
You can use map
to transform a column using a dictionary to define the transformation:
price_dict = 91:0, 65:1, 0:1, 20:1, 35:1, 32:1, 41:1, 36:1, 15:1, 90:1, 6:1, 67:1, 2:1, 57:1, 39:1, 1:1, 79:1, 34:1, 85:1 # not all
app['Price'] = app['Price'].map(price_dict)
app['Price'].value_counts()
You can also replace values in columns like this:
app['Price_new'] = 1
app.loc[app.Price == 91, 'Price_new'] = 0
You can use map
to transform a column using a dictionary to define the transformation:
price_dict = 91:0, 65:1, 0:1, 20:1, 35:1, 32:1, 41:1, 36:1, 15:1, 90:1, 6:1, 67:1, 2:1, 57:1, 39:1, 1:1, 79:1, 34:1, 85:1 # not all
app['Price'] = app['Price'].map(price_dict)
app['Price'].value_counts()
You can also replace values in columns like this:
app['Price_new'] = 1
app.loc[app.Price == 91, 'Price_new'] = 0
edited Mar 24 at 2:41
answered Mar 24 at 2:35
NathanielNathaniel
2,225314
2,225314
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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%2f55320244%2fhow-to-convert-values-in-df-by-loop%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