분류 전체보기 (130) 썸네일형 리스트형 for loop - 연습 1 # Initialize an empty dictionary: counts_dict counts_dict = {} # Iterate over the file chunk by chunk for chunk in pd.read_csv('tweets.csv', chunksize=10): # Iterate over the column in DataFrame for entry in chunk['lang']: if entry in counts_dict.keys(): counts_dict[entry] += 1 else: counts_dict[entry] = 1 # Print the populated dictionary print(counts_dict) - 연습 2 # Define count_entries().. [SQL] leetcode (easy) - Employees Earning More Than Their Managers 프로그래머스나 해커랭크의 easy보다 어려운 것 같음. Q. Write an SQL query to find the employees who earn more than their managers. Return the result table in any order. # Solution select name as Employee from employee e where salary > (select salary from Employee where id=e.managerId) # 다른사람 풀이 join 으로 푸는 방법들 # 1. SELECT e1.name as Employee from Employee e1, Employee e2 where e1.managerid = e2.id AND e1.salary > e2... [SQL] leetcode (medium) - second highest salary Q. Write an SQL query to report the second highest salary from the Employee table. If there is no second highest salary, the query should report null. # Solution 두번째로 salary가 큰 것을 가져오는거라 처음엔 window function을 사용해서 가져오려 했으나 max 를 사용하여 깔끔하게 해결 select max(salary) as SecondHighestSalary from employee where salary < (select max(salary) from employee) https://leetcode.com/problems/second-highest-salary.. Python Data Science Toolbox 3 - lambda function - 람다 함수 잘 모르겠어서 이 부분 더 찾아보기 - 연습 # Create a list of strings: fellowship fellowship = ['frodo', 'samwise', 'merry', 'pippin', 'aragorn', 'boromir', 'legolas', 'gimli', 'gandalf'] # Use filter() to apply a lambda function over fellowship: result result = filter(lambda member: len(member) > 6, fellowship) # Convert result to a list: result_list result_list = list(result) # Print result_list print(r.. Python Data Science Toolbox 2 - global scope : dened in the main body of a script - local scope : dened inside a function - Built-inscope : names in the pre-dened built-ins module 예를들어 위 슬라이드를 보면 new_val 이라는 변수를 함수 안에서 local scope로 정의해줬기 때문에 함수 밖에서 찍어보면 에러가 나는 것을 확인할 수 있다. 하지만 위 슬라이드 처럼 new_val을 함수 밖에서 global scope로 정의해주게 된다면 결과값을 제대로 확인할 수 있다. 하지만 결과값은 10이 아니라 9를 출력하는 이유는 함수 안에서 먼저 찾고 밖에서 값을 찾아주기 때문이다. 만약 함수 안 값이 없다면 함수 밖에서.. Python Data Science Toolbox 1 - def function - 연습 # Import pandas import pandas as pd # Import Twitter data as DataFrame: df df = pd.read_csv('tweets.csv') # Initialize an empty dictionary: langs_count langs_count = {} # Extract column from DataFrame: col col = df['lang'] # Iterate over lang column in DataFrame for entry in col: # If the language is in langs_count, add 1 if entry in langs_count.keys(): langs_count[entry] += 1 # Else add th.. [SQL] 해커랭크(HackerRank) Medium - Occupations Q. Pivot the Occupation column in OCCUPATIONS so that each Name is sorted alphabetically and displayed underneath its corresponding Occupation. The output column headers should be Doctor, Professor, Singer, and Actor, respectively. Note: Print NULL when there are no more names corresponding to an occupation. # Solution -> 아래와 같은 방식으로 sub query를 사용해서 진행했는데 틀렸다고 나옴.. select case when occupation oc.. [SQL] 해커랭크(HackerRank) Easy - Type of Triangles Q. Write a query identifying the type of each record in the TRIANGLES table using its three side lengths. Output one of the following statements for each record in the table: Equilateral: It's a triangle with 3 sides of equal length. Isosceles: It's a triangle with 2 sides of equal length. Scalene: It's a triangle with 3 sides of differing lengths. Not A Triangle: The given values of A, B, and C.. 이전 1 2 3 4 ··· 17 다음