Panda: read CSV datetime index plot

From OnnoWiki
Jump to navigation Jump to search


import pandas as pd
import glob

csv_file = '/home/onno/TensorFlow/TEMP-train.csv'
df = pd.read_csv(csv_file, names=['Time', 'Value'])
df['Time'] = pd.to_datetime(df['Time'], errors='coerce')
df['Value'] = pd.to_numeric(df['Value'], errors='coerce')

# print df
print df.head()
print df.shape
print df.dtypes

df = df.set_index('Time')
df = df.resample('1 Min').mean()

print df
print df.head()

import seaborn as sns
sns.set()
# df_plot = df_time.resample('M').mean()
df_plot = df
plt.plot(df_plot)
plt.title('Suhu')
plt.ylabel('Suhu (Celcius)')
plt.xticks(rotation=45)
plt.show()