Can you send some code so that I understand what you are talking about?
thanks for ur reply Main goal: cast a date column in a Panda's dataframe to datetime64[ns] 1 of the steps I'm in involves list comprehension, and the operation involves .astype to cast the current column (that matches "time|period|date" to datetime64[ns] My questions are:: - if/how can u cast type in-place ? - If not, if/how can u do assignment inside a list comprehension ? I've tried the following, none works so far, either dtype not changed or syntax error
dataframe used: column_0_date column_1_cat column_2_float column_3_int column_4_cat column_5_cat column_6_date column_7_float 0 2020-12-03 Barbara 20.411797 4 sheep Madrid 2020-12-08 86.298482 1 2020-09-10 Michael 16.679344 7 sheep Marseille 2020-12-20 49.4705 2 2020-10-14 James 49.41644 6 shrimp Stockholm 2020-01-18 20.290111 3 2020-04-06 Barbara 58.621822 1 crab Denver 2020-01-19 6.201747 4 2020-09-09 Robert 54.523121 5 fish Madrid 2020-08-08 96.107839
You want a good ol for loop, not a list comprehension as what you want isn't a new list, but to change something in place
Ya haha I realized I was only doing it out of habit, even if it's sometimes unpythonic I will go regular loop here Tho I do be curious still whether we could actually make it work with list comprehension, using some trickery, voodoo magic or otherwise, for science 👀👀
It should work, what error are you getting?
No error, but no change applied As I understand it most methods are not in place by default, working on copies instead So changes to the original dataframe won't "stick" unless u explicitly assign the changes to the original dataframe, or if the method has an inplace=True argument, or maybe copy=False .astype has the last one which I set but didn't seem to work
Обсуждают сегодня