코딩 테스트/Pandas

Invalid Tweets

susinlee 2024. 12. 19. 09:02

[문제]

Write a solution to find the IDs of the invalid tweets. The tweet is invalid if the number of characters used in the content of the tweet is strictly greater than 15.  Return the result table in any order.

 

 

[풀이]

1. content 컬럼의 길이가 15가 넘어가는 행들을 필터링

2. tweet_id 컬럼을 조회

 

Pandas

import pandas as pd

def invalid_tweets(tweets: pd.DataFrame) -> pd.DataFrame:
    # filter = tweets['content'].str.len() > 15 도 가능
    filter = tweets['content'].apply(len) > 15
    return tweets[filter][['tweet_id']]

 

SQL

SELECT tweet_id
FROM Tweets
WHERE LENGTH(content) > 15

 

'코딩 테스트 > Pandas' 카테고리의 다른 글

Rising Temperature  (0) 2024.12.21
Customer Who Visited but Did Not Make Any Transcations  (1) 2024.12.20
Product Sales Analysis 1  (0) 2024.12.20
대충 만든 자판  (0) 2024.12.19
Replace Employee ID With The Unique Identifier  (0) 2024.12.19