YesLod


























  1. sim existe uma carrada de transformaçoes nas messages antes de chegar à tabela, mas era para simplificar

  2. Ok, mas não respondeste à pergunta:

  3. sim também não dá pra inferir o tipo de messages pela imagem, mas enfim não uso python e odeio for loops prefiro as alternativas map/filter/reduce

  4. Fair enough, também sou fã de method chaining ;) mas não é tão comum em python. Nesse caso, preferia criar uma função com toda a lógica de processar a mensagem e usar algo como

  5. You don't need a loop. You can select all the numeric columns using DataFrame.select_dtypes method, and then use DataFrame.astype to convert them to integers.

  6. You can use Series.reindex to make sure that all the possible outcomes are part of the index. The outcomes not present in the original Series index are filled with NaN by default, but you can specify the fill value.

  7. gsmo says:

    I see. In that case you could 'cross filter' the two dataframes. Like so:

  8. This won't work, you can only compare identically-labeled DataFrames, i.e. with the same number of rows and same index (incluiding its order).

  9. gsmo says:

    Oh you're right, of course...

  10. That would work ;) but OP wants the filtering based on identical indexes, I think it's better if you change df1['A'] to df1.index and similar for df2

  11. Yes, using a tuple is the way (or any other object that is sorted lexicographically a list).

  12. oh, I was sure I removed this "different nested sorting" from the post(realized it's not required for the question and is rather overcomplication). Somehow editing did not saved well. Thank you for noticing though :)

  13. # while two consecutive spaces are in my_str

  14. gsmo says:

    This looks pretty good. In places it is a little overdocumented maybe but it does make the notebook very easy to read. The one thing you might experiment with is not using the apply method but instead setting those values using a mask.

  15. You can just use a boolean mask, i.e. mask = df['Time'] < 13, works fine with loc.

  16. You are misusing “is”. Look at the documentation and you will find that “is” will be true of the two objects being compared are the same object. Just remove it. Your statement should be “if sky_present:” not “if sky_present is True”

  17. Just to nit-pick, the use of is here is not necessarily incorrect. If OP wants to make sure that the block is executed if and only if sky_present is the boolean True (and not just a truthy value) using is is the indeed correct way ( True is a singleton). Of course this is irrelevant for this simple example, and using if sky_present is indeed more pythonic, but this distinction might be useful in other scenarios.

  18. IIUC, you just want a left join of the Series big_df with the DataFrame retrait_monthly on the Date column. You can do using the DataFrame.merge method as you said. I can't test it right now l, but the following should work

  19. *Assignment NEVER copies in Python.

  20. The problem is because filter return an iterator and not an actual list. x isn't evaluated until you execute the iterator and at that time (when you call list) x=3

  21. This is correct, and it is due to

  22. Series string methods, although useful and convenient, aren't truly vectorized. Still loops under the hood.

  23. No worries, I'm glad to help. I recommend this

  24. Just noticed that 'sum' gives me doubled values. If I remove margins_name, 'All' column has correct sum value, and 'sum' column seems to add it to rest of values.

  25. I can only help you if you show me all the relevant code which allows me to reproduce the same problem. What else are you adding to the code I gave you?

  26. Here are two different ways

  27. Thank you!! I did the first example and it worked great! You have been so much help to me during my project I really appreciate it! :)

  28. No problem! I'm glad to help!

  29. MATLAB also has closed indexing, not half-open like Python.

  30. Forgot about that detail.

  31. As a performance tip, you should always avoid using DataFrame.append method because it's very slow. DataFrames aren't lists, and shouldn't be treated as such. In this case, you should create a list of DataFrames and only concatenate them in the end, using

  32. Didn't know about that behaviour when y is 2D. It seems that matplotlib doesn't offer a straightforward solution according to these threads

  33. You sure? Giving it a second thought the ravel solution shouldn't work because t may not have the correct shape. But since you didn't show what t is, I can't be sure.

  34. You can combine all the columns first using the stack method.

  35. df['b_fact'] = df.groupby(['chain', 'res_num'])['b_fact'].transform('mean')

  36. No problem, I'm glad it helped. Yeah, whenever you want to preserve the shape of the original DataFrame you have to use transform. Thank you for the award!

  37. In the first example, you are applying the function to a DataFrame, a 2D data structure (contains two axes -- rows and columns). You have to specify the axis because the function can be either applied row-wise or column-wise.

  38. Yes, looks good. If you prefer, you can also use the

  39. there is this course on kaggle, this is one of the problems, and the set_index part is their solution, when I tried to do it the other way, it showed me error that it was incorrect

  40. Well, I can't help you without seeing the problem statement and their solution.

Leave a Reply

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

Author: admin