Strings
import pandas as pd
names = ['수연', '도하', '마준', '은지', '연아']
english_scores = [82, 95, 77, 82, 70]
math_scores = [45, 71, 96, 93, 80]
favorite_subjects = ['수학', '영어', '영어', '수학', '수학']
dict = {
'name': names,
'english score': english_scores,
'math score': math_scores,
'favorite': favorite_subjects
}
df = pd.DataFrame(dict)
df
name | english score | math score | favorite | |
---|---|---|---|---|
0 | 수연 | 82 | 45 | 수학 |
1 | 도하 | 95 | 71 | 영어 |
2 | 마준 | 77 | 96 | 영어 |
3 | 은지 | 82 | 93 | 수학 |
4 | 연아 | 70 | 80 | 수학 |
df.replace('수학', '과학')
name | english score | math score | favorite | |
---|---|---|---|---|
0 | 수연 | 82 | 45 | 과학 |
1 | 도하 | 95 | 71 | 영어 |
2 | 마준 | 77 | 96 | 영어 |
3 | 은지 | 82 | 93 | 과학 |
4 | 연아 | 70 | 80 | 과학 |
df
name | english score | math score | favorite | |
---|---|---|---|---|
0 | 수연 | 82 | 45 | 수학 |
1 | 도하 | 95 | 71 | 영어 |
2 | 마준 | 77 | 96 | 영어 |
3 | 은지 | 82 | 93 | 수학 |
4 | 연아 | 70 | 80 | 수학 |
df.replace({'수학': '이과', '영어':'문과'})
name | english score | math score | favorite | |
---|---|---|---|---|
0 | 수연 | 82 | 45 | 이과 |
1 | 도하 | 95 | 71 | 문과 |
2 | 마준 | 77 | 96 | 문과 |
3 | 은지 | 82 | 93 | 이과 |
4 | 연아 | 70 | 80 | 이과 |
ex = "korea is great"
table = str.maketrans('aieouAIEOU', 'AIEOUaieou')
ex.translate(table)
'kOrEA Is grEAt'
import re
paragraph = "Hi my name is Hong, Nice to meet you"
result = re.sub(pattern='\W', repl=' ', string=paragraph)
word_list =result.lower().split()
print(result)
print(word_list)
Hi my name is Hong Nice to meet you
['hi', 'my', 'name', 'is', 'hong', 'nice', 'to', 'meet', 'you']