December 18, 2019 at 12:00 am
Comments posted to this topic are about the item Renaming Columns
December 18, 2019 at 8:30 am
I thought I wouldn't touch this question until it's been reviewed, but I couldn't resist.
Clearly, option 3 wouldn't work, since the original column name is "BillingAmount", and not "BillAmount". In addition to that, since the Inplace parameter isn't set, option 3 would (if I understand things correctly) create a copy of the data frame with the column renamed.
December 18, 2019 at 11:33 am
Two small gripes on this one.
Option one won't work as it's renaming the wrong field.
Option 3 also won't work (as mentioned above) as the originating field name is different to that in the data frame.
From the given options, you would have to use the correct varioation of "BillingAmount" to get option 3 to work.
December 18, 2019 at 11:37 am
Option one won't work as it's renaming the wrong field.
Option one should work, shouldn't it, since it sets the name of all the columns, but uses the old name for column 1 and the new name for column 2?
December 18, 2019 at 11:48 am
Option 1 may well work, but in this instance, it's renaming the wrong field so is wrong for the question posted.
(I know, I'm being really picky now).
December 18, 2019 at 11:56 am
Option 1 may well work, but in this instance, it's renaming the wrong field so is wrong for the question posted.
(I know, I'm being really picky now).
I really don't follow this. Option 1 will name the first column "BillMonth" (which is a no-op) , and the second column "InvoiceAmount". The columns parameter isn't a map, it's just a list of column names.
December 18, 2019 at 1:51 pm
I thought I wouldn't touch this question until it's been reviewed, but I couldn't resist.
Clearly, option 3 wouldn't work, since the original column name is "BillingAmount", and not "BillAmount". In addition to that, since the Inplace parameter isn't set, option 3 would (if I understand things correctly) create a copy of the data frame with the column renamed.
+1
Thanks Rune, explained exactly, this can be verified by running the code.
December 18, 2019 at 4:38 pm
Option 1 works only if you replace the {} with [] as follows:
df.columns = ['BillMonth', 'InvoiceAmount']
LinkedIn: https://www.linkedin.com/in/sqlrv
Website: https://www.sqlrv.com
December 18, 2019 at 9:06 pm
Option 1 works only if you replace the {} with [] as follows:
df.columns = ['BillMonth', 'InvoiceAmount']
True, dat! So, we're down to the missing alternative of "None", I suppose...
December 18, 2019 at 11:22 pm
In Python Pandas (Python v2.7.13), option #1 works with both { } and [ ].
In addition, option #3 without the Inplace=True parameter will do nothing and the original df will not change.
Without the Inplace parameter, you can only make a new copy of the original df e.g like this:
df_new = df.rename (columns = {'BillingAmount': 'InvoiceAmount'})
print df_new #The column BillingAmount is renamed to InvoiceAmount
The explanation for QotD 2019-12-18 is very vague. Answer #5 is not true.
Viewing 10 posts - 1 through 9 (of 9 total)
You must be logged in to reply to this topic. Login to reply