Adding to the previous recipe, this recipe demonstrates more operations that can be performed on DataFrame objects: applying a function to all elements in a column, sorting based on a column, iterating over the rows, and concatenating multiple DataFrame objects vertically and horizontally.
Getting ready
Make sure you have followed the previous recipe before trying out this recipe. Ensure you have df in your Python namespace from the previous recipe.
How to do it…
Execute the following steps for this recipe:
- Import the necessary modules
>>> import random
>>> import pandas
- Modify the values in the timestamp column of df with a different date and time format DD-MM-YYYY HH:MM:SS:
>>> df['timestamp'] = df['timestamp'].apply(
lambda x: x.strftime("%d-%m-%Y %H:%M:%S"))
>>> df
We get the following output:
timestamp...