Plotting Salary vs. Names
Learn how to read data from a file and plot it in Python.
Reading data from a file
We have two following files:
-
names.txt
that contains names. -
salaries.txt
that contains salaries.
Let’s look at the files. We’re using the Linux cat command, which prints the file contents on the screen.
Lets run the following commands on the terminal below and see what happens.
cat names.txt
cat salaries.txt
The data in the two files are linked. So Fluffy would have a salary of 0, John would have a salary of 100, and so on. We’re using two different files to show different ways of reading data.
salary = np.fromfile("salaries.txt", dtype=int, sep=",")
NumPy arrays have versatility that makes them much better than standard Python lists because they allow different numeric data types. Python lists are mainly used for strings. While the lists can store numbers, they aren’t optimized for numerical processing. NumPy arrays are. We can store data as 8, 16, or 32 bits. We can choose to use integers or floats. NumPy handles all the conversion and ...
Get hands-on with 1400+ tech skills courses.