MCPcopy Create free account
hub / github.com/Apress/modern-pyqt / loadCSVFile

Method loadCSVFile

ch03_data_visualization/data_visualization.py:255–281  ·  view source on GitHub ↗

Load data from CSV file for the chart. Select and store x and y values and labels into Python list objects. Return the xy_data_and_labels list.

(self)

Source from the content-addressed store, hash-verified

253 self.axis_y.setRange(0, 40)
254
255 def loadCSVFile(self):
256 """Load data from CSV file for the chart.
257 Select and store x and y values and labels into Python list objects.
258 Return the xy_data_and_labels list."""
259 file_name = "files/social_spending_simplified.csv"
260
261 with open(file_name, "r") as csv_f:
262 reader = csv.reader(csv_f)
263 header_labels = next(reader)
264
265 row_values = [] # Store current row values
266 xy_data_and_labels = [] # Store all values
267
268 for i, row in enumerate(reader):
269 x = int(row[2])
270 y = float(row[3])
271 label = row[0]
272
273 row_values.append(x)
274 row_values.append(y)
275 row_values.append(label)
276
277 # Add row_values to xy_data_and_labels, then reset row_values
278 xy_data_and_labels.append(row_values)
279 row_values = []
280
281 return xy_data_and_labels
282
283if __name__ == "__main__":
284 app = QApplication(sys.argv)

Callers 1

setupChartMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected