How to manipulate a CSV file for Matplotlib using Python -


if have following data , want draw multiple-line graph representing following [a snippet of] data, in format in csv file:

the data:

1216,c210,3610 1217,c210,1863 1218,c210,2419 1224,c210,861 1299,c210,2517 1216,c211,3593 1217,c211,1849 1218,c211,2410 1224,c211,859 1299,c211,2504 1216,c212,3595 1217,c212,1847 1218,c212,2407 1224,c212,860 1299,c212,2501 

the goal:

i visually represent data as: data being represented in csv file

q: how can manipulate csv data can create such graph matplotlib , python?

the sticky: have done far got stuck:

def processing_and_graphing(m_list, c_list):     open(csv_dump, 'r') input_csv_dump_file:         input_csv = csv.reader(input_csv_dump_file, delimiter=',', skipinitialspace=false)          open(csv_temp, 'w', newline='') output_csv_temp_file:         machine in m_list:             write_into_csv_file = csv.writer(output_csv_temp_file, delimiter=',', quoting=csv.quote_minimal)              row in input_csv:                 if row[0] == machine: 

the difficulty: having:

i'm have tremendous difficulty in trying reorganise data can give matplotlib.

the approach: thinking approach:

is iterate through csv file , dump data temp file, can use generate graph (could directly csv or panda or alternative method). stuck in trying rearrange data.

this 1 possible approach problem. reads csv file , converts pandas dataframe. after loops through ids , creates plot. left out eventual changes make plot nicer (like correctly labeling x axis). hope can you.

import pandas pd import numpy np import matplotlib.pyplot plt  data = np.genfromtxt('file.csv', delimiter=',', dtype=none) df =  pd.dataframe(data) ids = df.f0.drop_duplicates() id in ids:     id_data = df[df['f0'] == id]     plt.plot([0,1,2], id_data['f2'].as_matrix()) plt.show() 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -