- Bài 1: Tìm hiểu về pandas
- Bài 2: Hướng dẫn cài đặt pandas
- Bài 3: Giới thiệu về cấu trúc dữ liệu
- Bài 4: Series
- Bài 5: DataFrame
- Bài 6: Panel
- Bài 7: Hàm cơ bản - Series
- Bài 8: Các hàm cơ bản : DataFrame
- Bài 9: Thống kê
- Bài 10: Ứng dụng Hàm
- Bài 11: Đọc dữ liệu và kĩ thuật reindexing
- Bài 12: Iteration ( Duyệt phần tử)
- Bài 13: Sort ( Sắp xếp )
- Bài 14: Làm việc với dữ liệu Text (P1)
- Bài 15: Làm việu với dữ liệu Text (p2)
- Bài 16: Options và Customize
- Bài 17: Data Selection và Indexing trong Pandas - p1
- Bài 18: Data Selection và Indexing trong Pandas - p2
- Bài 19: Hàm thống kê
- Bài 20: Hàm Window
- Bài 21: Aggregate
- Bài 22: Missing Data ( Thiếu dữ liệu )
- Bài 23: GroupBy (Nhóm dữ liệu) - p1
- Bài 24: GroupBy (Nhóm dữ liệu)- P2
- Bài 25: Joining/merging
Bài 15: Làm việu với dữ liệu Text (p2) - Python Panda
Đăng bởi: Admin | Lượt xem: 1112 | Chuyên mục: Python
split(pattern)
import pandas as pd
import numpy as np
s = pd.Series(['Tom ', ' William Rick', 'John', 'Alber@t'])
print s
print ("Split Pattern:")
print s.str.split(' ')
Kết quả :
0 Tom
1 William Rick
2 John
3 Alber@t
dtype: object
Split Pattern:
0 [Tom, , , , , , , , , , ]
1 [, , , , , William, Rick]
2 [John]
3 [Alber@t]
dtype: object
cat(sep=pattern)
import pandas as pd
import numpy as np
s = pd.Series(['Tom ', ' William Rick', 'John', 'Alber@t'])
print s.str.cat(sep='_')
Kết quả :
Tom _ William Rick_John_Alber@t
get_dummies()
import pandas as pd
import numpy as np
s = pd.Series(['Tom ', ' William Rick', 'John', 'Alber@t'])
print s.str.get_dummies()
Kết quả :
William Rick Alber@t John Tom
0 0 0 0 1
1 1 0 0 0
2 0 0 1 0
3 0 1 0 0
contains ()
import pandas as pd
s = pd.Series(['Tom ', ' William Rick', 'John', 'Alber@t'])
print s.str.contains(' ')
Kết quả :
0 True
1 True
2 False
3 False
dtype: bool
replace(a,b)
import pandas as pd
s = pd.Series(['Tom ', ' William Rick', 'John', 'Alber@t'])
print s
print ("After replacing @ with $:")
print s.str.replace('@','$')
Kết quả :
0 Tom
1 William Rick
2 John
3 Alber@t
dtype: object
After replacing @ with $:
0 Tom
1 William Rick
2 John
3 Alber$t
dtype: object
repeat(value)
import pandas as pd
s = pd.Series(['Tom ', ' William Rick', 'John', 'Alber@t'])
print s.str.repeat(2)
Kết quả :
0 Tom Tom
1 William Rick William Rick
2 JohnJohn
3 Alber@tAlber@t
dtype: object
count(pattern)
import pandas as pd
s = pd.Series(['Tom ', ' William Rick', 'John', 'Alber@t'])
print ("The number of 'm's in each string:")
print s.str.count('m')
Kết quả :
The number of 'm's in each string:
0 1
1 1
2 0
3 0
startswith(pattern)
import pandas as pd
s = pd.Series(['Tom ', ' William Rick', 'John', 'Alber@t'])
print ("Strings that start with 'T':")
print s.str. startswith ('T')
Kết quả :
0 True
1 False
2 False
3 False
dtype: bool
endswith(pattern)
import pandas as pd
s = pd.Series(['Tom ', ' William Rick', 'John', 'Alber@t'])
print ("Strings that end with 't':")
print s.str.endswith('t')
Kết quả :
Strings that end with 't':
0 False
1 False
2 False
3 True
dtype: bool
find(pattern)
import pandas as pd
s = pd.Series(['Tom ', ' William Rick', 'John', 'Alber@t'])
print s.str.find('e')
Kết quả :
0 -1
1 -1
2 -1
3 3
dtype: int64
"-1" cho biết rằng phần tử không có pattern như vậy.
findall(pattern)
import pandas as pd
s = pd.Series(['Tom ', ' William Rick', 'John', 'Alber@t'])
print s.str.findall('e')
Kết quả :
0 []
1 []
2 []
3 [e]
dtype: object
Danh sách rỗng ([]) có nghĩa không có sẵn pattern trong phần tử.
swapcase()
import pandas as pd
s = pd.Series(['Tom', 'William Rick', 'John', 'Alber@t'])
print s.str.swapcase()
Kết quả :
0 tOM
1 wILLIAM rICK
2 jOHN
3 aLBER@T
dtype: object
islower()
import pandas as pd
s = pd.Series(['Tom', 'William Rick', 'John', 'Alber@t'])
print s.str.islower()
Kết quả :
0 False
1 False
2 False
3 False
dtype: bool
isupper()
import pandas as pd
s = pd.Series(['Tom', 'William Rick', 'John', 'Alber@t'])
print s.str.isupper()
Kết quả :
0 False
1 False
2 False
3 False
dtype: bool
isnumeric()
import pandas as pd
s = pd.Series(['Tom', 'William Rick', 'John', 'Alber@t'])
print s.str.isnumeric()
Kết quả :
0 False
1 False
2 False
3 False
dtype: bool
Theo dõi VnCoder trên Facebook, để cập nhật những bài viết, tin tức và khoá học mới nhất!
- Bài 1: Tìm hiểu về pandas
- Bài 2: Hướng dẫn cài đặt pandas
- Bài 3: Giới thiệu về cấu trúc dữ liệu
- Bài 4: Series
- Bài 5: DataFrame
- Bài 6: Panel
- Bài 7: Hàm cơ bản - Series
- Bài 8: Các hàm cơ bản : DataFrame
- Bài 9: Thống kê
- Bài 10: Ứng dụng Hàm
- Bài 11: Đọc dữ liệu và kĩ thuật reindexing
- Bài 12: Iteration ( Duyệt phần tử)
- Bài 13: Sort ( Sắp xếp )
- Bài 14: Làm việc với dữ liệu Text (P1)
- Bài 15: Làm việu với dữ liệu Text (p2)
- Bài 16: Options và Customize
- Bài 17: Data Selection và Indexing trong Pandas - p1
- Bài 18: Data Selection và Indexing trong Pandas - p2
- Bài 19: Hàm thống kê
- Bài 20: Hàm Window
- Bài 21: Aggregate
- Bài 22: Missing Data ( Thiếu dữ liệu )
- Bài 23: GroupBy (Nhóm dữ liệu) - p1
- Bài 24: GroupBy (Nhóm dữ liệu)- P2
- Bài 25: Joining/merging