Pandas & Numpy data wrangling
import pandas as pd
import numpy as np
Unix timestamp to a python datetime
object, and set as the index:
df['timestamp'] = pd.to_datetime(df['timestamp'], unit='ms')
df = df.set_index('timestamp')
And from a datetime
object to a unix timestamp:
df.index.astype(np.int64) // 10**6
Multiple columns to a numeric type:
for (column_name, _) in df.items():
if column_name == 'timestamp' or column_name == 'some-column-that-contains-strings':
continue
df[column_name] = pd.to_numeric(df[column_name], errors='coerce')