What’s causing inconsistent behavior using Pandas? /u/JagerMunster Python Education

I was trying to add a column to a dataframe and and paste in some values from an excel sheet. When I ran:

dataframe[dataframe.columns[-1] + timedelta(1)] = 0 dataframe.iloc[:,-1] = fill.iloc[:,-1] 

(where fill is a dataframe created by reading the excel file) in a Jupyter cell or pasted into the command line or as part of a function, it created the column and then filled every row with NA, presumably related to a mismatch in index labels, but when I ran dataframe.iloc[:,-1] = fill.iloc[:,-1] in another cell or seperately at the command prompt, it copied over the values row-by-row, as desired.

Now, I know the correct way to do this is to match the indices, or use .values, or deprecate the excel file for another input method, all of which work just fine, but whats causing the same line of code to have different outcomes depending on how I execute it?

submitted by /u/JagerMunster
[link] [comments]

​r/learnpython I was trying to add a column to a dataframe and and paste in some values from an excel sheet. When I ran: dataframe[dataframe.columns[-1] + timedelta(1)] = 0 dataframe.iloc[:,-1] = fill.iloc[:,-1] (where fill is a dataframe created by reading the excel file) in a Jupyter cell or pasted into the command line or as part of a function, it created the column and then filled every row with NA, presumably related to a mismatch in index labels, but when I ran dataframe.iloc[:,-1] = fill.iloc[:,-1] in another cell or seperately at the command prompt, it copied over the values row-by-row, as desired. Now, I know the correct way to do this is to match the indices, or use .values, or deprecate the excel file for another input method, all of which work just fine, but whats causing the same line of code to have different outcomes depending on how I execute it? submitted by /u/JagerMunster [link] [comments] 

I was trying to add a column to a dataframe and and paste in some values from an excel sheet. When I ran:

dataframe[dataframe.columns[-1] + timedelta(1)] = 0 dataframe.iloc[:,-1] = fill.iloc[:,-1] 

(where fill is a dataframe created by reading the excel file) in a Jupyter cell or pasted into the command line or as part of a function, it created the column and then filled every row with NA, presumably related to a mismatch in index labels, but when I ran dataframe.iloc[:,-1] = fill.iloc[:,-1] in another cell or seperately at the command prompt, it copied over the values row-by-row, as desired.

Now, I know the correct way to do this is to match the indices, or use .values, or deprecate the excel file for another input method, all of which work just fine, but whats causing the same line of code to have different outcomes depending on how I execute it?

submitted by /u/JagerMunster
[link] [comments] 

Leave a Reply

Your email address will not be published. Required fields are marked *