“panda jika lain” Kode Jawaban

PANDAS IF PYTHON

import pandas as pd

names = {'First_name': ['Jon','Bill','Maria','Emma']}
df = pd.DataFrame(names,columns=['First_name'])

df.loc[(df['First_name'] == 'Bill') | (df['First_name'] == 'Emma'), 'name_match'] = 'Match'  
df.loc[(df['First_name'] != 'Bill') & (df['First_name'] != 'Emma'), 'name_match'] = 'Mismatch'  

print (df)
maNu

PANDAS IF PYTHON

df['new column name'] = df['column name'].apply(lambda x: 'value if condition is met' if x condition else 'value if condition is not met')
Calm Crab

Jika Kondisi DataFrame Python

df.loc[df['age1'] - df['age2'] > 0, 'diff'] = df['age1'] - df['age2']
Glorious Goldfinch

panda jika lain

df.loc[df['column name'] condition, 'new column name'] = 'value if condition is met'
Fragile Finch

PANDAS IF PYTHON

import pandas as pd

numbers = {'set_of_numbers': [1,2,3,4,5,6,7,8,9,10]}
df = pd.DataFrame(numbers,columns=['set_of_numbers'])

df['equal_or_lower_than_4?'] = df['set_of_numbers'].apply(lambda x: 'True' if x <= 4 else 'False')

print (df)
NA RACE

PANDAS IF PYTHON

import pandas as pd

names = {'First_name': ['Jon','Bill','Maria','Emma']}
df = pd.DataFrame(names,columns=['First_name'])

df.loc[df['First_name'] == 'Bill', 'name_match'] = 'Match'  
df.loc[df['First_name'] != 'Bill', 'name_match'] = 'Mismatch'  
 
print (df)
maNu

Jawaban yang mirip dengan “panda jika lain”

Pertanyaan yang mirip dengan “panda jika lain”

Lebih banyak jawaban terkait untuk “panda jika lain” di Python

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya