Question

In: Computer Science

I'm working on a scatter-plot program in Python using Pandas, Matplotlib, Numpy, etc. I'm pulling data...

I'm working on a scatter-plot program in Python using Pandas, Matplotlib, Numpy, etc. I'm pulling data from a CSV file, which has no names, just numbers. All I did was to read a .csv file. How do I pull data from three columns which contains about 1500 rows with just numbers and make a scatter plot with two in the x-axis and the third in the y-axis?

Solutions

Expert Solution

import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
file_path = "./inp.csv"
#read_csv() function helps in reading the csv file
#header=None will take care of that
#usecols attribute helps in reading specific column indexes for your problem
#3 columns only. x , y1, y2 are the three columns new names
#names aattribute for setting names for the columns that read helps in plotting
df = pd.read_csv(file_path, header=None, usecols=[0,1,2],names=["x","y1","y2"])

#once data frame is created
#assign the scatter plot of the given data frame in variable
#x = "x" means on x axis use x column data in data frame read
#y = "y2" means on y axis use y2 column data in data frame read
#color to distinguish and label is to say what the points of given color
ax = df.plot(kind="scatter", x="x",y="y2", color="b", label="x vs. y2")

#next plot another scatter plot but now use on x axis y1 and on y axis y2 columns data
#and ax attribute is the axes.
#set it to the previous plot x vs y2
df.plot(kind="scatter", x="y1",y="y2", color="r", label="y1 vs. y2", ax=ax)
#print the columns and data frame
# you may not need theese two prints coz you will have huge data. so
#if you dont want to print comment below two print statements
print(df.columns)
print(df)
#set labels
ax.set_xlabel("horizontal label")
ax.set_ylabel("vertical label")
#finally show the plot.
plt.show()

#if you have any doubts please comment and like the answer.


Related Solutions

#Python program using loop instead of numpy or pandas. Write a function to enter n student...
#Python program using loop instead of numpy or pandas. Write a function to enter n student scores from 0 to 100 to represent student score, Count how many A (100 - 90), B(89-80), C(79-70), D(69-60), F(<60) We will use numpy array OR pandas later for this problem, for now use loop Invoke the function with 10 student scores, show the result as follow: Test Enter 10 scores Enter a student score: 99 Enter a student score: 88 Enter a student...
#All the code solutions should only use Pandas/Numpy and Matplotlib. Initialize the US Zipcode dataset as...
#All the code solutions should only use Pandas/Numpy and Matplotlib. Initialize the US Zipcode dataset as shown below: usZipCodeData = pd.read_csv('http://people.bu.edu/kalathur/datasets/uszips.csv', converters={'zip': lambda x: str(x)}) Q1. Show the top 20 zip codes for Massachusetts by the decreasing order of density attribute. Q2. Show the top 20 zip codes for Massachusetts by the decreasing order of population attribute. Q3. What zip codes are common between Q8 and Q9. Use the numpy intersect1d method. Q4. For Massachusetts, show a scatter plot of...
Using Python coding language (with or without Pandas and/or NumPy), 1. Can you define function sleep...
Using Python coding language (with or without Pandas and/or NumPy), 1. Can you define function sleep to tell whether the participant are of the ages through 18 to 60 and sleep less than 6 hours per day? 2. Develop codes to check whether the sleep function you defined can make correct judgement. Make sure you write comments or create informative vairable name so that I can understand how you check the sleep function. (Hints: You can create toy data/dataframe to...
The purpose of this is to plot data using Matplotlib. Description complete the Jupyter notebook named...
The purpose of this is to plot data using Matplotlib. Description complete the Jupyter notebook named main.ipynb that reads in the file diamonds.csv into a Pandas DataFrame. Information about the file can be found here: ------- diamonds R Documentation Prices of over 50,000 round cut diamonds Description A dataset containing the prices and other attributes of almost 54,000 diamonds. The variables are as follows: Usage diamonds Format A data frame with 53940 rows and 10 variables: price price in US...
I'm working on a to-do list program in Python 2. I'm trying to delete an item...
I'm working on a to-do list program in Python 2. I'm trying to delete an item from the list and I'm not sure what I'm missing to do that. I haven't been able to get it to delete by string or by index number. Also, I'm trying to get the menu to run again after the user completes the add/delete/etc options. Do I need to put menu() menu_option = int(input("Welcome to your To-Do List. Please choose and option to continue:...
Pandas exercises: 1. Write a python program using Pandas to create and display a one-dimensional array-like...
Pandas exercises: 1. Write a python program using Pandas to create and display a one-dimensional array-like object containing an array of data. 2. Write a python program using Pandas to convert a Panda module Series to Python list and print it's type. (Hint: use ds.tolist() to convert the pandas series ds to a list) 3. Create a pandas dataframe called **my_df** with index as integer numbers between 0 to 10, first column (titled "rnd_int") as 10 integer random numbers between...
Generate a scatter plot of this data, and include a smoothed function using smooth.spline function in...
Generate a scatter plot of this data, and include a smoothed function using smooth.spline function in R. Use predict function in R to calculate the 95% bounds (confidence band) for the mean, and plot them on the same scatterplot (use lty=2, and col=3). How would I go about writing this code in R?
Graphs with Matplotlib Using the library Matplotlib and the provided data files create the following graphs:...
Graphs with Matplotlib Using the library Matplotlib and the provided data files create the following graphs: I) Pie chart Create a pie chart that shows the percentage of employees in each department within a company. The provided file: employee_count_by_department.txt contains the data required in order to generate this pie chart. II) Line Graph Create a line graph that shows a company's profit over the past ten years. The provided file: last_ten_year_net_profit.txt contains the data required in order to generate this...
Below are four bivariate data sets and the scatter plot for each. (Note that each scatter...
Below are four bivariate data sets and the scatter plot for each. (Note that each scatter plot is displayed on the same scale.) Each data set is made up of sample values drawn from a population. x y 1.0 10.0 2.0 9.0 3.0 8.0 4.0 7.0 5.0 6.0 6.0 5.0 7.0 4.0 8.0 3.0 9.0 2.0 10.0 1.0 x 1 2 3 4 5 6 7 8 9 10 11 y 1 2 3 4 5 6 7 8 9...
a. Construct a scatter plot of the data. Determine the order of the polynomial that is represented by this data.
  Consider the following data: x 1 4 5 7 8 12 11 14 19 20 y 1 54 125 324 512 5,530 5,331 5,740 7,058 7,945 Use Excel to resolve: a. Construct a scatter plot of the data. Determine the order of the polynomial that is represented by this data. b. Obtain an estimate of the model identified in part a. c. Conduct a test of hypothesis to determine if a third- order, as opposed to a first-order, polynomial...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT