在Python中,熊猫通过分隔符(:)将数据帧拆分为列,以保留现有列(数据清理)
我有以下几点在Python中,熊猫通过分隔符(:)将数据帧拆分为列,以保留现有列(数据清理),python,pandas,Python,Pandas,我有以下几点 23 Don Cheadle 2885.4 34 84.9 Avengers: Age of Ultron 459 Don Cheadle YEs 24 Ben Stiller:2827.0:37:76.4:Meet the Fockers:27... NaN NaN NaN NaN NaN NaN NaN NaN 我需要像这样的东西 23 Don Cheadle 2885.4 34 84.9 Avengers: Age of Ultron 459
23 Don Cheadle 2885.4 34 84.9 Avengers: Age of Ultron 459 Don Cheadle YEs
24 Ben Stiller:2827.0:37:76.4:Meet the Fockers:27... NaN NaN NaN NaN NaN NaN NaN NaN
我需要像这样的东西
23 Don Cheadle 2885.4 34 84.9 Avengers: Age of Ultron 459 Don Cheadle YEs
24 Ben Stiller 2827.0 37 76.4 Meet the Fockers 279.3 Ben Stiller Yes
我试过了
df['Actor'].str.split(':',expand=True)
但结果如下:
23 Don Cheadle None None None None None None None None
24 Ben Stiller 2827.0 37 76.4 Meet the Fockers 279.3 Ben Stiller Yes
i、 e它将值替换为无
我使用的数据集是:
Actor Total Gross Number of Movies Average per Movie #1 Movie Gross Firstname Lastname Price
0 Harrison Ford 4871.7 41 118.8 Star Wars: The Force Awakens 936.7 Harrison Ford yes
1 Samuel Jackson 4772.8 69 69.2 The Avengers 623.4 Samuel Jackson no
2 Morgan Freeman 4468.3 61 73.3 The Dark Knight 534.9 Morgan Freeman Yes
3 Tom Hanks 4340.8 44 98.7 Toy Story 3 415 Tom Hanks No
4 Robert Downey 3947.3 53 74.5 The Avengers 623.4 Robert Downey yes
5 Eddie Murphy 3810.4 38 100.3 Shrek 2 441.2 Eddie Murphy no
6 Tom Cruise 3587.2 36 99.6 War of the Worlds 234.3 Tom Cruise yes
7 Johnny Depp 3368.6 45 74.9 Dead Mans Chest 423.3 Johnny Depp No
8 Michael Caine 3351.5 58 57.8 The Dark Knight 534.9 Michael Caine NO
9 Scarlett Johansson 3341.2 37 90.3 The Avengers 623.4 Scarlett Johansson n0
10 Gary Oldman 3294 38 86.7 The Dark Knight 534.9 Gary Oldman No
11 Robin Williams 3279.3 49 66.9 Night at the Museum 250.9 Robin Williams no
12 Bruce Willis 3189.4 60 53.2 Sixth Sense 293.5 Bruce Willis no
13 Stellan Skarsgard 3175 43 73.8 The Avengers 623.4 Stellan Skarsgard yes
14 Anthony Daniels 3162.9 7 451.8 Star Wars: The Force Awakens 936.7 Anthony Daniels no
15 Ian McKellen 3150.4 31 101.6 Return of the King 377.8 Ian McKellen No
16 Will Smith 3149.1 24 131.2 Independence Day 306.2 Will Smith no
17 Stanley Tucci 3123.9 50 62.5 Catching Fire 424.7 Stanley Tucci yes
18 Matt Damon 3107.3 39 79.7 The Martian 228.4 Matt Damon no
19 Robert DeNiro 3081.3 79 39 Meet the Fockers 279.3 Robert DeNiro No
20 Cameron Diaz 3031.7 34 89.2 Shrek 2 441.2 Cameron Diaz No
21 Liam Neeson 2942.7 63 46.7 The Phantom Menace -474.5 Liam Neeson No
22 Andy Serkis 2890.6 23 125.7 Star Wars: The Force Awakens 936.7 Andy Serkis Yes
23 Don Cheadle 2885.4 34 84.9 Avengers: Age of Ultron 459 Don Cheadle YEs
24 Ben Stiller:2827.0:37:76.4:Meet the Fockers:27... NaN NaN NaN NaN NaN NaN NaN NaN
你能提供MRE吗?发布你正在使用的数据using@ombk,发布了我正在使用的数据。我想你应该在ben stiller的Row上应用转换格式。你能提供MRE吗?发布你正在使用的数据using@ombk,发布了我正在使用的数据。我想你应该在本·斯蒂勒的行上应用转换格式