“pandas si más” Código de respuesta

Pandas si 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 si 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

Si la condición DataFrame Python

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

pandas si más

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

Pandas si 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 si 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

Respuestas similares a “pandas si más”

Preguntas similares a “pandas si más”

Más respuestas relacionadas con “pandas si más” en Python

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código