Difference between revisions of "Panda: read csv datetime"
Jump to navigation
Jump to search
Onnowpurbo (talk | contribs) |
Onnowpurbo (talk | contribs) |
||
Line 5: | Line 5: | ||
x = pandas.read_csv('/home/onno/TensorFlow/TEMP-train.csv', parse_dates=True, index_col='DateTime', | x = pandas.read_csv('/home/onno/TensorFlow/TEMP-train.csv', parse_dates=True, index_col='DateTime', | ||
names=['DateTime', 'X'], header=None, sep=',') | names=['DateTime', 'X'], header=None, sep=',') | ||
− | x | + | print(x) |
+ | x.info() | ||
==Cara 2== | ==Cara 2== |
Revision as of 09:01, 7 August 2019
Cara 1
import pandas x = pandas.read_csv('/home/onno/TensorFlow/TEMP-train.csv', parse_dates=True, index_col='DateTime', names=['DateTime', 'X'], header=None, sep=',') print(x) x.info()
Cara 2
import numpy as np import matplotlib.pyplot as plt import pandas as pd infile = '/home/onno/TensorFlow/TEMP-train.csv' mydateparser = lambda x: pd.datetime.strptime(x, "%Y-%m-%d %H:%M:%S") df = pd.read_csv(infile, sep=',', names=['datetime', 'value'], parse_dates=['datetime'], date_parser=mydateparser)