Skip to content

feat: add pandas solution to lc problem: No.0550 #1891

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Oct 27, 2023
Merged

Conversation

nrhitik
Copy link
Contributor

@nrhitik nrhitik commented Oct 27, 2023

No description provided.

@idoocs
Copy link
Member

idoocs commented Oct 27, 2023

🤭 感谢你的提交,请检查你的改动是否符合以下项目规范。

1. 格式化

我们项目中各种编程语言代码(包括文档)所采用的格式化工具不同,提交 pr 之前必须确保代码、文档正确格式化。

  • .{md,js,ts,php,sql} 采用 prettier
  • .{c,cpp,java} 采用 clang-format
  • .{py} 采用 black
  • .{go} 采用 gofmt
  • 其它待完善

2. Git 提交信息

我们项目遵循 AngularJS Git Commit Message Conventions 规范,我们希望你的提交信息尽可能与项目保持一致。

  • 新增或修改题解:feat: add/update solution(s) to lc problem(s): No.xxxx
  • 修复错误:fix: xxxx
  • 日常维护:chore: xxx

3. 其它补充

新增题解及代码时,需要创建 Solution.xxx 源代码文件(如果已存在,请确认算法是否更优,是则覆盖已有算法代码),同时,需要在 README.md 以及 README_EN.md 中添加对应的代码片段(英文文件中不要出现中文注释)

另外,编码风格(比如变量、函数的命名),尽量跟项目已有代码保持一致。


🤭 Thank you for your contribution. Please check if your changes comply with the following project specifications.

1. Formatting

We use different formatting tools for various programming languages (including documentation) in our project. You must ensure that the code and documentation are correctly formatted before submitting a pr.

  • .{md,js,ts,php,sql} use prettier
  • .{c,cpp,java} use clang-format
  • .{py} use black
  • .{go} use gofmt
  • Others to be improved

2. Git Commit Message

Our project follows the AngularJS Git Commit Message Conventions. We hope that your submission information is as consistent as possible with the project.

  • Add or modify solutions: feat: add/update solution(s) to lc problem(s): No.xxxx
  • Fix errors: fix: xxxx
  • Routine maintenance: chore: xxx

3. Other notes

When adding solutions and code, you need to create a Solution.xxx source code file (if it already exists, please confirm whether the algorithm is better, if yes, overwrite the existing algorithm code), and at the same time, you need to add the corresponding code snippets in README.md and README_EN.md (do not have Chinese comments in the English file)

In addition, the coding style (such as the naming of variables and functions) should be as consistent as possible with the existing code in the project.

@idoocs idoocs added md Issues or Pull requests relate to .md files py Issues or Pull requests relate to .py code labels Oct 27, 2023
@nrhitik
Copy link
Contributor Author

nrhitik commented Oct 27, 2023

I've resoulved to issues.

@thinkasany
Copy link
Member

I've resoulved to issues.

Can you provide a reason why you're sticking with loc, because I've looked into it and found that it's actually better to omit it.

- activity_2nd_day = activity.loc[
-       activity["first"] + pd.DateOffset(1) == activity["event_date"]
-  ]
+ activity_2nd_day = activity[activity["first"] + pd.DateOffset(1) == activity["event_date"]]

The optimized code provides several advantages:

Improved Performance: By using boolean indexing instead of the loc method, unnecessary data copying is reduced, resulting in improved code execution efficiency. The loc method often requires creating a new data copy, while using boolean indexing does not, making it faster, especially with large datasets.

Simplicity of Code: The optimized code is more concise and easier to read. It avoids the use of the loc method, reducing redundant code and making it easier to understand and maintain.

Enhanced Readability: Using boolean indexing directly expresses the filtering conditions, making the code clearer and more intuitive. There is no need for extra method calls or redundant operations, making the code's intent easier to grasp.

@nrhitik
Copy link
Contributor Author

nrhitik commented Oct 27, 2023

oh actually I replaced the loc with bool indexing but i must have forgotten to commit the changes I guess let me do it again.

@nrhitik
Copy link
Contributor Author

nrhitik commented Oct 27, 2023

I've made the changes. Can you take a look at it?

@thinkasany
Copy link
Member

thinkasany commented Oct 27, 2023

oh actually I replaced the loc with bool indexing but i must have forgotten to commit the changes I guess let me do it again.

Can you change it to one line?

@thinkasany
Copy link
Member

I've made the changes. Can you take a look at it?

There's nothing else wrong with it. Just change it to one line and it'll fit. @nrhitik

@nrhitik
Copy link
Contributor Author

nrhitik commented Oct 27, 2023

I can do that but, I have set Black format on save on my local machine. So every time I hit Ctrl+S it changes the format of my .py file to black. I can change it to one line but will it stay in black format? Let me know you still need it one line, I'll change it.

@thinkasany thinkasany merged commit 8be44f3 into doocs:main Oct 27, 2023
@thinkasany
Copy link
Member

I can do that but, I have set Black format on save on my local machine. So every time I hit Ctrl+S it changes the format of my .py file to black. I can change it to one line but will it stay in black format? Let me know you still need it one line, I'll change it.

I'm sorry. It's my fault. You're right.

@thinkasany
Copy link
Member

thinkasany commented Oct 27, 2023

This pr still contains extra commits, next time you can pay attention to it, you can learn about the use of rebase, that will definitely help you, it can not have to create switching branches frequently, and it is also helpful for you to develop the specification later. Solution for 511 is not a required commit for this pr, not important but better to know. You can refer to the history pr's commit details, I believe that one is the best case in point.Thanks again for your contribution! @nrhitik

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
md Issues or Pull requests relate to .md files py Issues or Pull requests relate to .py code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants