leetcode(28)
-
[LeetCode] Python3 / 125. Valid Palindrome
1. 문제 링크https://leetcode.com/problems/valid-palindrome/ 2. 문제 3. 소스 코드 및 해설#전체 코드class Solution: def isPalindrome(self, s: str) -> bool: strs = [] for char in s: if char.isalnum(): strs.append(char.lower()) while len(strs) > 1: if strs.pop(0) != strs.pop(): #맨 앞 글자와 맨 뒷 글자 비교 return False return True1) cha..
2024.10.07 -
[LeetCode] Pandas / 2891. Method Chaining
문제 링크https://leetcode.com/problems/method-chaining/description/ 문제 코드import pandas as pddef findHeavyAnimals(animals: pd.DataFrame) -> pd.DataFrame: return animals[animals['weight']>100].sort_values(['weight'], ascending=False)[['name']]
2024.07.08 -
[LeetCode] Pandas / 2890. Reshape data: Melt
문제 링크https://leetcode.com/problems/reshape-data-melt/description/ 문제 코드import pandas as pddef meltTable(report: pd.DataFrame) -> pd.DataFrame: return report.melt(id_vars=['product'], var_name='quarter', value_name='sales')
2024.07.08 -
[LeetCode] Pandas / 2889. Reshape data: Pivot
문제 링크https://leetcode.com/problems/reshape-data-pivot/description/ 문제 코드import pandas as pddef pivotTable(weather: pd.DataFrame) -> pd.DataFrame: return weather.pivot(index='month', columns='city', values='temperature')
2024.07.08 -
[LeetCode] Pandas / 2888. Reshape data concatenate
문제 링크https://leetcode.com/problems/reshape-data-concatenate/description/ 문제 코드 import pandas as pddef concatenateTables(df1: pd.DataFrame, df2: pd.DataFrame) -> pd.DataFrame: return pd.concat([df1, df2])
2024.07.08 -
[LeetCode] Pandas / 2887. Fill missing data
문제 링크https://leetcode.com/problems/fill-missing-data/description/ 문제 코드 import pandas as pddef fillMissingValues(products: pd.DataFrame) -> pd.DataFrame: products["quantity"]=products["quantity"].fillna(0) return products
2024.07.08