Muller Unlimited

View Original

April 19, 2020

Looking at Types

  1. To see the types of each column of a DataFrame, we can use print(df.dtypes)

  2. The data types Pandas uses are:

    1. float

    2. int

    3. bool

    4. datetime

    5. timedelta

    6. category

    7. object

  3. We can use what we know of regex to get rid of dollar signs:

    1. fruit.prices = fruit[‘price’].replace(‘[\$,]’,’’,regex=True)

  4. We can use the Pandas function .to_nameric( ) to convert strings containing numerical values to integers or floats:

    1. fruit.price = pd.to_numeric(fruit.price)

  5. To extract the numbers from a string, we can use Pandas .str.split( ) function:

    1. split_df = df[‘exerciseDescription’].str_split(‘(\dt)’, expand = True)