Похожие чаты

Guys does assignment works in list comprehension for u ?

7 ответов

9 просмотров

Can you send some code so that I understand what you are talking about?

Dumbo- Автор вопроса
MrObjectOriented Ass
Can you send some code so that I understand what y...

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

Dumbo- Автор вопроса
Dumbo
screenshot thanks for ur reply Main goal: cast a date column...

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

Dumbo
screenshot thanks for ur reply Main goal: cast a date column...

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

Dumbo- Автор вопроса
harꭑony5 🐦‍🔥 ↺
You want a good ol for loop, not a list comprehens...

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 👀👀

Dumbo- Автор вопроса
harꭑony5 🐦‍🔥 ↺
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

Похожие вопросы

Обсуждают сегодня

Комрады, хотел уточнить. Проперть в OnDestroy юнита-хозяина по-прежнему доступна? И еще уточнение: finalization юнита наступает раньше или позже OnDestroy?
Ed Doc
38
Здравствуйте! Есть вопросы по ПК: 1.1. Безопасно ли запускать программы, которым я не доверяю, в виртуальной машине под KVM+qemu? (x86_64) 1.2. То же самое при использовании ...
Pavel
5
Проблема с Windows scripting control Множество объектов получают iDispatch обертки и отдаются в скрипты. При этом скрипты могут эти обертки держать живыми очень долго, наприм...
Arioch The
16
Hi everyone! I have a two-folded message to share today. First: updates and news, as we are being asked for those. We still want to go like we did the last 6 years: we w...
Marten | Unibright.io
31
Я тут пытаюсь переработать архитектуру подсистемы памяти ядра во что-то осмысленное. Есть pmm, который создает набор range’ей(пока что только для ядра, потом для юзерспейса), ...
Evg Resh
9
Скажите, можно ли как-то "переместить" динамический массив из одной переменной в другую? Скажем, переместить из TList<> в TArray<>. Именно переместить, а не скопировать. Если ...
Eugene Krasnikov (ᴊɪɴ x)
37
У меня вопрос, а какой уровень оптимизации ставить при сборке на i5 4 ядра 16G ddr3 ОЗУ и видюха Geforce GTX 970?
Sir Jiga
18
Guys, what’s the most expensive part of your budget for your business/startup/app/website?
Ice Kream
18
What is the best and safest exchange to trade XMR ? with no kyc ...obviously 👍
cabbageflaps
12
Oh.... Admins at the main TG is already muted me. How many months Sir you muted me? Or forever if you are here @Janevietani @JohnnySonic
Charles Dar
28
Карта сайта