getting nan on added column












0















In a dataframe rebinnedDF, I wanted to add another column that has repeated random row values. I create that value as repeateArray.



    year2014_bin    year2015_bin    year2016_bin    year2017_bin
0 binZ binZ binZ binZ
1 binZ binZ binZ binZ
repeateArray=[x for x in range (0, rebinnedDF.shape[0]/len(rebinnedDF.columns))]

repeateArray =rebinnedDF.join(pd.DataFrame (repeateArray))


when I do repeateArray[0][:2] which is the added column, I get nan. Should not that have valued based on the list comprehension above.



    year2014_bin    year2015_bin    year2016_bin    year2017_bin    0
0 binZ binZ binZ binZ nan
1 binZ binZ binZ binZ nan


4 binZ binZ binZ binZ nan
5 binZ binZ binZ binZ nan
6 binZ binZ binZ binZ nan
7 binZ binZ binZ binZ nan
8 binZ binZ binZ binZ nan
9 binZ binZ binZ binZ nan


Desired. I want `0` to be randomly repeated based on the length of the dataframe. I have 6 million rows. Number of repetition really does not matter.

year2014_bin year2015_bin year2016_bin year2017_bin 0
0 binZ binZ binZ binZ 1
1 binZ binZ binZ binZ 2
2 binZ binZ binZ binZ 3
3 binZ binZ binZ binZ 4
4 binZ binZ binZ binZ 1
.............









share|improve this question

























  • Hi John, Just added to it. Thanks

    – lpt
    Nov 25 '18 at 0:16











  • Your code gives 'float' object cannot be interpreted as an integer. Are you really using Python 3? If your code runs, please check that what you've posted here is your actual code and not a broken version of it. Maybe the problem is your example has too few rows? Anyway what you've posted doesn't work at all.

    – John Zwinck
    Nov 25 '18 at 0:23













  • Sorry, it was Python 2.7.15. then how would append either of the datatypes in the dataframe which has randomly repeated values based on the length fo the column

    – lpt
    Nov 25 '18 at 0:28













  • reformatted with more data. Does this make more sense now?

    – lpt
    Nov 25 '18 at 0:35











  • So you're using Python 2.7 but you tagged the question with Python 3? I give up.

    – John Zwinck
    Nov 25 '18 at 0:40
















0















In a dataframe rebinnedDF, I wanted to add another column that has repeated random row values. I create that value as repeateArray.



    year2014_bin    year2015_bin    year2016_bin    year2017_bin
0 binZ binZ binZ binZ
1 binZ binZ binZ binZ
repeateArray=[x for x in range (0, rebinnedDF.shape[0]/len(rebinnedDF.columns))]

repeateArray =rebinnedDF.join(pd.DataFrame (repeateArray))


when I do repeateArray[0][:2] which is the added column, I get nan. Should not that have valued based on the list comprehension above.



    year2014_bin    year2015_bin    year2016_bin    year2017_bin    0
0 binZ binZ binZ binZ nan
1 binZ binZ binZ binZ nan


4 binZ binZ binZ binZ nan
5 binZ binZ binZ binZ nan
6 binZ binZ binZ binZ nan
7 binZ binZ binZ binZ nan
8 binZ binZ binZ binZ nan
9 binZ binZ binZ binZ nan


Desired. I want `0` to be randomly repeated based on the length of the dataframe. I have 6 million rows. Number of repetition really does not matter.

year2014_bin year2015_bin year2016_bin year2017_bin 0
0 binZ binZ binZ binZ 1
1 binZ binZ binZ binZ 2
2 binZ binZ binZ binZ 3
3 binZ binZ binZ binZ 4
4 binZ binZ binZ binZ 1
.............









share|improve this question

























  • Hi John, Just added to it. Thanks

    – lpt
    Nov 25 '18 at 0:16











  • Your code gives 'float' object cannot be interpreted as an integer. Are you really using Python 3? If your code runs, please check that what you've posted here is your actual code and not a broken version of it. Maybe the problem is your example has too few rows? Anyway what you've posted doesn't work at all.

    – John Zwinck
    Nov 25 '18 at 0:23













  • Sorry, it was Python 2.7.15. then how would append either of the datatypes in the dataframe which has randomly repeated values based on the length fo the column

    – lpt
    Nov 25 '18 at 0:28













  • reformatted with more data. Does this make more sense now?

    – lpt
    Nov 25 '18 at 0:35











  • So you're using Python 2.7 but you tagged the question with Python 3? I give up.

    – John Zwinck
    Nov 25 '18 at 0:40














0












0








0








In a dataframe rebinnedDF, I wanted to add another column that has repeated random row values. I create that value as repeateArray.



    year2014_bin    year2015_bin    year2016_bin    year2017_bin
0 binZ binZ binZ binZ
1 binZ binZ binZ binZ
repeateArray=[x for x in range (0, rebinnedDF.shape[0]/len(rebinnedDF.columns))]

repeateArray =rebinnedDF.join(pd.DataFrame (repeateArray))


when I do repeateArray[0][:2] which is the added column, I get nan. Should not that have valued based on the list comprehension above.



    year2014_bin    year2015_bin    year2016_bin    year2017_bin    0
0 binZ binZ binZ binZ nan
1 binZ binZ binZ binZ nan


4 binZ binZ binZ binZ nan
5 binZ binZ binZ binZ nan
6 binZ binZ binZ binZ nan
7 binZ binZ binZ binZ nan
8 binZ binZ binZ binZ nan
9 binZ binZ binZ binZ nan


Desired. I want `0` to be randomly repeated based on the length of the dataframe. I have 6 million rows. Number of repetition really does not matter.

year2014_bin year2015_bin year2016_bin year2017_bin 0
0 binZ binZ binZ binZ 1
1 binZ binZ binZ binZ 2
2 binZ binZ binZ binZ 3
3 binZ binZ binZ binZ 4
4 binZ binZ binZ binZ 1
.............









share|improve this question
















In a dataframe rebinnedDF, I wanted to add another column that has repeated random row values. I create that value as repeateArray.



    year2014_bin    year2015_bin    year2016_bin    year2017_bin
0 binZ binZ binZ binZ
1 binZ binZ binZ binZ
repeateArray=[x for x in range (0, rebinnedDF.shape[0]/len(rebinnedDF.columns))]

repeateArray =rebinnedDF.join(pd.DataFrame (repeateArray))


when I do repeateArray[0][:2] which is the added column, I get nan. Should not that have valued based on the list comprehension above.



    year2014_bin    year2015_bin    year2016_bin    year2017_bin    0
0 binZ binZ binZ binZ nan
1 binZ binZ binZ binZ nan


4 binZ binZ binZ binZ nan
5 binZ binZ binZ binZ nan
6 binZ binZ binZ binZ nan
7 binZ binZ binZ binZ nan
8 binZ binZ binZ binZ nan
9 binZ binZ binZ binZ nan


Desired. I want `0` to be randomly repeated based on the length of the dataframe. I have 6 million rows. Number of repetition really does not matter.

year2014_bin year2015_bin year2016_bin year2017_bin 0
0 binZ binZ binZ binZ 1
1 binZ binZ binZ binZ 2
2 binZ binZ binZ binZ 3
3 binZ binZ binZ binZ 4
4 binZ binZ binZ binZ 1
.............






python pandas python-2.7






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 27 '18 at 15:53









Ivan Kolesnikov

1,26111032




1,26111032










asked Nov 24 '18 at 23:55









lptlpt

335111




335111













  • Hi John, Just added to it. Thanks

    – lpt
    Nov 25 '18 at 0:16











  • Your code gives 'float' object cannot be interpreted as an integer. Are you really using Python 3? If your code runs, please check that what you've posted here is your actual code and not a broken version of it. Maybe the problem is your example has too few rows? Anyway what you've posted doesn't work at all.

    – John Zwinck
    Nov 25 '18 at 0:23













  • Sorry, it was Python 2.7.15. then how would append either of the datatypes in the dataframe which has randomly repeated values based on the length fo the column

    – lpt
    Nov 25 '18 at 0:28













  • reformatted with more data. Does this make more sense now?

    – lpt
    Nov 25 '18 at 0:35











  • So you're using Python 2.7 but you tagged the question with Python 3? I give up.

    – John Zwinck
    Nov 25 '18 at 0:40



















  • Hi John, Just added to it. Thanks

    – lpt
    Nov 25 '18 at 0:16











  • Your code gives 'float' object cannot be interpreted as an integer. Are you really using Python 3? If your code runs, please check that what you've posted here is your actual code and not a broken version of it. Maybe the problem is your example has too few rows? Anyway what you've posted doesn't work at all.

    – John Zwinck
    Nov 25 '18 at 0:23













  • Sorry, it was Python 2.7.15. then how would append either of the datatypes in the dataframe which has randomly repeated values based on the length fo the column

    – lpt
    Nov 25 '18 at 0:28













  • reformatted with more data. Does this make more sense now?

    – lpt
    Nov 25 '18 at 0:35











  • So you're using Python 2.7 but you tagged the question with Python 3? I give up.

    – John Zwinck
    Nov 25 '18 at 0:40

















Hi John, Just added to it. Thanks

– lpt
Nov 25 '18 at 0:16





Hi John, Just added to it. Thanks

– lpt
Nov 25 '18 at 0:16













Your code gives 'float' object cannot be interpreted as an integer. Are you really using Python 3? If your code runs, please check that what you've posted here is your actual code and not a broken version of it. Maybe the problem is your example has too few rows? Anyway what you've posted doesn't work at all.

– John Zwinck
Nov 25 '18 at 0:23







Your code gives 'float' object cannot be interpreted as an integer. Are you really using Python 3? If your code runs, please check that what you've posted here is your actual code and not a broken version of it. Maybe the problem is your example has too few rows? Anyway what you've posted doesn't work at all.

– John Zwinck
Nov 25 '18 at 0:23















Sorry, it was Python 2.7.15. then how would append either of the datatypes in the dataframe which has randomly repeated values based on the length fo the column

– lpt
Nov 25 '18 at 0:28







Sorry, it was Python 2.7.15. then how would append either of the datatypes in the dataframe which has randomly repeated values based on the length fo the column

– lpt
Nov 25 '18 at 0:28















reformatted with more data. Does this make more sense now?

– lpt
Nov 25 '18 at 0:35





reformatted with more data. Does this make more sense now?

– lpt
Nov 25 '18 at 0:35













So you're using Python 2.7 but you tagged the question with Python 3? I give up.

– John Zwinck
Nov 25 '18 at 0:40





So you're using Python 2.7 but you tagged the question with Python 3? I give up.

– John Zwinck
Nov 25 '18 at 0:40












0






active

oldest

votes











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
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53463465%2fgetting-nan-on-added-column%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































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.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53463465%2fgetting-nan-on-added-column%23new-answer', 'question_page');
}
);

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







Popular posts from this blog

404 Error Contact Form 7 ajax form submitting

How to know if a Active Directory user can login interactively

Refactoring coordinates for Minecraft Pi buildings written in Python