{"id":23653579,"url":"https://github.com/abhishekmishragithub/gitbook-notes","last_synced_at":"2025-11-19T09:30:17.214Z","repository":{"id":220283007,"uuid":"751227372","full_name":"abhishekmishragithub/gitbook-notes","owner":"abhishekmishragithub","description":"Random notes","archived":false,"fork":false,"pushed_at":"2024-04-02T11:10:55.000Z","size":23,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-12-28T17:54:26.560Z","etag":null,"topics":["notes","programming","python","system-design"],"latest_commit_sha":null,"homepage":"https://stalwartcoder.gitbook.io/abhishek-notes/","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/abhishekmishragithub.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2024-02-01T07:22:16.000Z","updated_at":"2024-02-01T07:25:36.000Z","dependencies_parsed_at":null,"dependency_job_id":"3eb15939-00c3-434f-a9c2-d36d08403623","html_url":"https://github.com/abhishekmishragithub/gitbook-notes","commit_stats":null,"previous_names":["abhishekmishragithub/gitbook-notes"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abhishekmishragithub%2Fgitbook-notes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abhishekmishragithub%2Fgitbook-notes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abhishekmishragithub%2Fgitbook-notes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abhishekmishragithub%2Fgitbook-notes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/abhishekmishragithub","download_url":"https://codeload.github.com/abhishekmishragithub/gitbook-notes/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239619570,"owners_count":19669447,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["notes","programming","python","system-design"],"created_at":"2024-12-28T17:54:30.681Z","updated_at":"2025-11-19T09:30:17.146Z","avatar_url":"https://github.com/abhishekmishragithub.png","language":null,"readme":"---\ndescription: Some notes/code snippet related to pandas operations.\n---\n\n# Pandas notes\n\n## Apply a function with multiple arguments to pandas DataFrame columns - using DataFrame.apply()\n\n`DataFrame.apply()` applies a function along an axis of the DataFrame.\u0026#x20;\n\nFollowing is the syntax:\n\n```python\nDataFrame.apply(func, axis=0, raw=False, result_type=None, args=(), **kwds)\n```\n\n{% hint style=\"info\" %}\nReference: [https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.apply.html](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.apply.html)\n{% endhint %}\n\nUse `args=(param1, param2, )` parameter in `DataFrame.apply()` method to pass additional arguments to a function.\n\nIt takes function parameters in a tuple. The first argument is series by default so you don't need to pass it.\n\n**Example:** Convert an ISO date/DateTime stamp (_`2021-04-12T07:21:00.345344`_) to standard  \\\n(`2021-04-10 07:21:00.345344`) format.\n\n{% code title=\"apply_test.py\" %}\n```python\nimport pandas as pd\n\ndef date_to(row, col_name):\n''' Function to convert an ISO date format to standard date format'''\n        row[col_name] = pd.to_datetime(row[col_name]).strftime('%Y-%m-%d %H:%M%:%S.%f')\n        #row[col_name] = pd.to_datetime(row[col_name]).strftime('%Y-%m-%d %H:%M%:%S.%f')[:-3]\n        return row[col_name]\n\n\nsample_dates = {\n            \"Date\": [\n                \"2021-04-12T07:21:00.345344\",\n                \"2015-10-19T07:18:00.234234\",\n                \"2018-11-19T07:15:00.423423\",\n            ],\n            \"AnotherDate\": [\n                \"2018-12-22T07:21:00.963344\",\n                \"2019-08-19T07:18:00.887234\",\n                \"2020-03-20T07:15:00.765423\",\n            ]\n        }\n        \ndf = pd.DataFrame(s2)\n# df['Date'] = df.apply(date_to, axis=1) :apply function without paramter.\ndf[\"Date\"] = df.apply(date_to, args=(\"Date\",), axis=1) # apply function with paramter.\ndf[\"AnontherDate\"] = df.apply(date_to, args=(\"AnontherDate\",), axis=1)\n```\n{% endcode %}\n\n#### Output**:**\n\n```python\n                         Date                AnotherDate\n0  2021-04-12 07:21:00.345344  2018-12-22 07:21:00.963344\n1  2015-10-19 07:18:00.234234  2019-08-19 07:18:00.887234\n2  2018-11-19 07:15:00.423423  2020-03-20 07:15:00.765423\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabhishekmishragithub%2Fgitbook-notes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fabhishekmishragithub%2Fgitbook-notes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabhishekmishragithub%2Fgitbook-notes/lists"}