Strings
Columns containing strings are represented as the object type in Pandas.
Since a lot of data you will encounter involve strings, it is important that you know how to manipulate them.
Python allows you to use its built-in string manipulation methods with the str accessor. There are several string methods, some of which are .upper() and .lower(). They convert strings to upper and lower case, respectively.
# Converts 'col_a' to lower case
df['col_a'].str.lower()
# Converts 'col_b' to upper case
df['col_b'].str.upper()
Este ejercicio forma parte del curso
Python for R Users
Instrucciones del ejercicio
- Inspect the
'sex'and'smoker'columns in the shell. - Convert the
'sex'column into lower case. - Convert the
'smoker'column into upper case. - Inspect the
'sex'and'smoker'columns to ensure that case conversion worked.
Ejercicio interactivo práctico
Prueba este ejercicio y completa el código de muestra.
# Convert sex to lower case
tips____ = tips____
# Convert smoker to upper case
tips____ = tips____
# Print the sex and smoker columns
print(tips[['sex', 'smoker']])