如何 select 两个数据框之间具有相同值的行?
How to select the row with same value in between two data frames?
我有以下庞大的数据集,包含许多不同的应用程序名称和发送属性下的情绪:
App Sent
0 10 Best Foods for You Positive
1 10 Best Foods for You Positive
2 10 Best Foods for You NaN
3 10 Best Foods for You Positive
4 10 Best Foods for You Positive
5 10 Best Foods for You Positive
6 10 Best Foods for You Positive
7 10 Best Foods for You NaN
8 10 Best Foods for You Neutral
9 10 Best Foods for You Neutral
10 10 Best Foods for You Positive
11 10 Best Foods for You Positive
12 10 Best Foods for You Positive
13 10 Best Foods for You Positive
... ...
64289 Houzz Interior Design Ideas NaN
64290 Houzz Interior Design Ideas NaN
64291 Houzz Interior Design Ideas NaN
64292 Houzz Interior Design Ideas NaN
64293 Houzz Interior Design Ideas NaN
64294 Houzz Interior Design Ideas NaN`
我想找出产生大致相同正面和负面情绪比率的应用程序(即找到具有相同数量正面和负面情绪或最接近第一的应用程序)
我尝试将上面的数据框分成两个数据框,其值分别为正值和负值。
然后分组然后计数
例如:
正数据帧 p:
Sent
App
10 Best Foods for You 162
104 找工作 - 找工作 找打工 找兼職 履歷健檢 履歷診療室 31
11st 23
1800 Contacts - Lens Store 64
1LINE – One Line with One Touch 27
2018Emoji Keyboard Emoticons Lite -sticker&gif 25
21-Day Meditation Experience 68
2Date Dating App, Love and matching 26
2GIS: directory & navigator 23
2RedBeans 31
2ndLine - Second Phone Number 17
30 Day Fitness Challenge - Workout at Home 27
365Scores - Live Scores 5
3D Live Neon Weed Launcher 2
4 in a Row 17
7 Day Food Journal Challenge 9
7 Minute Workout 10
7 Weeks - Habit & Goal Tracker 10
8 Ball Pool 104
850 Sports News Digest 38
8fit Workouts & Meal Planner 137
95Live -SG#1 Live Streaming App 34
A Call From Santa Claus! 20
A Word A Day 3
A&E - Watch Full Episodes of TV Shows 30
A+ Gallery - Photos & Videos 24
...
HipChat - Chat Built for Teams 19
Hipmunk Hotels & Flights 30
Hitwe - meet people and chat 2
Hole19: Golf GPS App, Rangefinder & Scorecard 18
Home Decor Showpiece Art making: Medium Difficulty 16
Home Scouting® MLS Mobile 13
Home Security Camera WardenCam - reuse old phones 18
Home Street – Home Design Game 42
Home Workout - No Equipment 24
Home Workout for Men - Bodybuilding 22
Home workouts - fat burning, abs, legs, arms,chest 8
HomeWork 1
Homes.com For Sale, Rent 11
Homescapes 27
Homesnap Real Estate & Rentals 25
Homestyler Interior Design & Decorating Ideas 19
Homework Planner 33
Honkai Impact 3rd 54
Hopper - Watch & Book Flights 54
Horoscopes – Daily Zodiac Horoscope and Astrology 21
Horses Live Wallpaper 22
Hostelworld: Hostels & Cheap Hotels Travel App 42
Hot Wheels: Race Off 14
HotelTonight: Book amazing deals at great hotels 93
Hotels Combined - Cheap deals 15
Hotels.com: Book Hotel Rooms & Find Vacation Deals 39
Hotspot Shield Free VPN Proxy & Wi-Fi Security 17
Hotstar 14
Hotwire Hotel & Car Rental App 16
Housing-Real Estate & Property 8
[853 rows x 1 columns]
负数据帧 n:
Sent
App
10 Best Foods for You 10
104 找工作 - 找工作 找打工 找兼職 履歷健檢 履歷診療室 1
11st 7
1800 Contacts - Lens Store 6
1LINE – One Line with One Touch 8
2018Emoji Keyboard Emoticons Lite -sticker&gif 1
21-Day Meditation Experience 10
2Date Dating App, Love and matching 7
2GIS: directory & navigator 6
2RedBeans 2
2ndLine - Second Phone Number 7
30 Day Fitness Challenge - Workout at Home 2
4 in a Row 3
7 Minute Workout 1
7 Weeks - Habit & Goal Tracker 4
8 Ball Pool 106
850 Sports News Digest 1
8fit Workouts & Meal Planner 19
95Live -SG#1 Live Streaming App 20
A Call From Santa Claus! 14
A&E - Watch Full Episodes of TV Shows 3
A+ Gallery - Photos & Videos 7
A+ Mobile 9
ABC Kids - Tracing & Phonics 1
ABC News - US & World News 29
ABC Preschool Free 8
...
Hill Climb Racing 13
Hill Climb Racing 2 11
Hily: Dating, Chat, Match, Meet & Hook up 29
Hinge: Dating & Relationships 11
HipChat - Chat Built for Teams 26
Hipmunk Hotels & Flights 1
Hitwe - meet people and chat 7
Home Decor Showpiece Art making: Medium Difficulty 5
Home Scouting® MLS Mobile 12
Home Security Camera WardenCam - reuse old phones 4
Home Street – Home Design Game 13
Home Workout - No Equipment 1
Homes.com For Sale, Rent 3
Homescapes 25
Homesnap Real Estate & Rentals 6
Homestyler Interior Design & Decorating Ideas 7
Homework Planner 4
Honkai Impact 3rd 22
Hopper - Watch & Book Flights 18
Horoscopes – Daily Zodiac Horoscope and Astrology 1
Horses Live Wallpaper 2
Hostelworld: Hostels & Cheap Hotels Travel App 12
Hot Wheels: Race Off 6
HotelTonight: Book amazing deals at great hotels 17
Hotels Combined - Cheap deals 7
Hotels.com: Book Hotel Rooms & Find Vacation Deals 21
Hotspot Shield Free VPN Proxy & Wi-Fi Security 3
Hotstar 14
Hotwire Hotel & Car Rental App 6
Housing-Real Estate & Property 10
[782 rows x 1 columns]
这样做我可以找到等于 p["Sent"].values:
的应用程序名称
df=p.loc[p["Sent"]==n["Sent"]]
print(df)
Output:
ValueError: Can only compare identically-labeled Series objects
您正在比较具有不同行的数据帧。
我会这样做。考虑这种情况。
name p n
app1 5 5
app2 8 6
app3 7 7
app4 10 8
app5 3 NaN
此代码打印应用名称和编号,其中 'p' 和 'n' 编号相同。
# make dataframe p, n
p = pd.DataFrame([5, 8, 7, 10 ,3], index=['app1', 'app2', 'app3', 'app4', 'app5'], columns=['p'])
n = pd.DataFrame([5, 6, 7, 8, None], index=['app1', 'app2', 'app3', 'app4', 'app5'], columns=['n'])
# combine p and n with concat
df = pd.concat([p, n], axis=1)
# check equality
for i in range(len(df)):
if df.iloc[i]['p'] == df.iloc[i]['n']:
print(df.index[i], df.iloc[i]['p'])
# Outputs are
# app1 5.0
# app3 7.0
我有以下庞大的数据集,包含许多不同的应用程序名称和发送属性下的情绪:
App Sent
0 10 Best Foods for You Positive
1 10 Best Foods for You Positive
2 10 Best Foods for You NaN
3 10 Best Foods for You Positive
4 10 Best Foods for You Positive
5 10 Best Foods for You Positive
6 10 Best Foods for You Positive
7 10 Best Foods for You NaN
8 10 Best Foods for You Neutral
9 10 Best Foods for You Neutral
10 10 Best Foods for You Positive
11 10 Best Foods for You Positive
12 10 Best Foods for You Positive
13 10 Best Foods for You Positive
... ...
64289 Houzz Interior Design Ideas NaN
64290 Houzz Interior Design Ideas NaN
64291 Houzz Interior Design Ideas NaN
64292 Houzz Interior Design Ideas NaN
64293 Houzz Interior Design Ideas NaN
64294 Houzz Interior Design Ideas NaN`
我想找出产生大致相同正面和负面情绪比率的应用程序(即找到具有相同数量正面和负面情绪或最接近第一的应用程序) 我尝试将上面的数据框分成两个数据框,其值分别为正值和负值。 然后分组然后计数 例如: 正数据帧 p:
Sent
App
10 Best Foods for You 162
104 找工作 - 找工作 找打工 找兼職 履歷健檢 履歷診療室 31
11st 23
1800 Contacts - Lens Store 64
1LINE – One Line with One Touch 27
2018Emoji Keyboard Emoticons Lite -sticker&gif 25
21-Day Meditation Experience 68
2Date Dating App, Love and matching 26
2GIS: directory & navigator 23
2RedBeans 31
2ndLine - Second Phone Number 17
30 Day Fitness Challenge - Workout at Home 27
365Scores - Live Scores 5
3D Live Neon Weed Launcher 2
4 in a Row 17
7 Day Food Journal Challenge 9
7 Minute Workout 10
7 Weeks - Habit & Goal Tracker 10
8 Ball Pool 104
850 Sports News Digest 38
8fit Workouts & Meal Planner 137
95Live -SG#1 Live Streaming App 34
A Call From Santa Claus! 20
A Word A Day 3
A&E - Watch Full Episodes of TV Shows 30
A+ Gallery - Photos & Videos 24
...
HipChat - Chat Built for Teams 19
Hipmunk Hotels & Flights 30
Hitwe - meet people and chat 2
Hole19: Golf GPS App, Rangefinder & Scorecard 18
Home Decor Showpiece Art making: Medium Difficulty 16
Home Scouting® MLS Mobile 13
Home Security Camera WardenCam - reuse old phones 18
Home Street – Home Design Game 42
Home Workout - No Equipment 24
Home Workout for Men - Bodybuilding 22
Home workouts - fat burning, abs, legs, arms,chest 8
HomeWork 1
Homes.com For Sale, Rent 11
Homescapes 27
Homesnap Real Estate & Rentals 25
Homestyler Interior Design & Decorating Ideas 19
Homework Planner 33
Honkai Impact 3rd 54
Hopper - Watch & Book Flights 54
Horoscopes – Daily Zodiac Horoscope and Astrology 21
Horses Live Wallpaper 22
Hostelworld: Hostels & Cheap Hotels Travel App 42
Hot Wheels: Race Off 14
HotelTonight: Book amazing deals at great hotels 93
Hotels Combined - Cheap deals 15
Hotels.com: Book Hotel Rooms & Find Vacation Deals 39
Hotspot Shield Free VPN Proxy & Wi-Fi Security 17
Hotstar 14
Hotwire Hotel & Car Rental App 16
Housing-Real Estate & Property 8
[853 rows x 1 columns]
负数据帧 n:
Sent
App
10 Best Foods for You 10
104 找工作 - 找工作 找打工 找兼職 履歷健檢 履歷診療室 1
11st 7
1800 Contacts - Lens Store 6
1LINE – One Line with One Touch 8
2018Emoji Keyboard Emoticons Lite -sticker&gif 1
21-Day Meditation Experience 10
2Date Dating App, Love and matching 7
2GIS: directory & navigator 6
2RedBeans 2
2ndLine - Second Phone Number 7
30 Day Fitness Challenge - Workout at Home 2
4 in a Row 3
7 Minute Workout 1
7 Weeks - Habit & Goal Tracker 4
8 Ball Pool 106
850 Sports News Digest 1
8fit Workouts & Meal Planner 19
95Live -SG#1 Live Streaming App 20
A Call From Santa Claus! 14
A&E - Watch Full Episodes of TV Shows 3
A+ Gallery - Photos & Videos 7
A+ Mobile 9
ABC Kids - Tracing & Phonics 1
ABC News - US & World News 29
ABC Preschool Free 8
...
Hill Climb Racing 13
Hill Climb Racing 2 11
Hily: Dating, Chat, Match, Meet & Hook up 29
Hinge: Dating & Relationships 11
HipChat - Chat Built for Teams 26
Hipmunk Hotels & Flights 1
Hitwe - meet people and chat 7
Home Decor Showpiece Art making: Medium Difficulty 5
Home Scouting® MLS Mobile 12
Home Security Camera WardenCam - reuse old phones 4
Home Street – Home Design Game 13
Home Workout - No Equipment 1
Homes.com For Sale, Rent 3
Homescapes 25
Homesnap Real Estate & Rentals 6
Homestyler Interior Design & Decorating Ideas 7
Homework Planner 4
Honkai Impact 3rd 22
Hopper - Watch & Book Flights 18
Horoscopes – Daily Zodiac Horoscope and Astrology 1
Horses Live Wallpaper 2
Hostelworld: Hostels & Cheap Hotels Travel App 12
Hot Wheels: Race Off 6
HotelTonight: Book amazing deals at great hotels 17
Hotels Combined - Cheap deals 7
Hotels.com: Book Hotel Rooms & Find Vacation Deals 21
Hotspot Shield Free VPN Proxy & Wi-Fi Security 3
Hotstar 14
Hotwire Hotel & Car Rental App 6
Housing-Real Estate & Property 10
[782 rows x 1 columns]
这样做我可以找到等于 p["Sent"].values:
的应用程序名称df=p.loc[p["Sent"]==n["Sent"]]
print(df)
Output:
ValueError: Can only compare identically-labeled Series objects
您正在比较具有不同行的数据帧。
我会这样做。考虑这种情况。
name p n
app1 5 5
app2 8 6
app3 7 7
app4 10 8
app5 3 NaN
此代码打印应用名称和编号,其中 'p' 和 'n' 编号相同。
# make dataframe p, n
p = pd.DataFrame([5, 8, 7, 10 ,3], index=['app1', 'app2', 'app3', 'app4', 'app5'], columns=['p'])
n = pd.DataFrame([5, 6, 7, 8, None], index=['app1', 'app2', 'app3', 'app4', 'app5'], columns=['n'])
# combine p and n with concat
df = pd.concat([p, n], axis=1)
# check equality
for i in range(len(df)):
if df.iloc[i]['p'] == df.iloc[i]['n']:
print(df.index[i], df.iloc[i]['p'])
# Outputs are
# app1 5.0
# app3 7.0