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...
Using Python, generate 100 random numbers ranging from 1 to 5, then plot them using matplotlib...
Using Python, generate 100 random numbers ranging from 1 to 5, then plot them using matplotlib or Seaborn as a histogram
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?
Create and Compile a Python Script without using Numpy that Generate an nxn matrix using Python...
Create and Compile a Python Script without using Numpy that Generate an nxn matrix using Python Script (ie n=user input) Ask (user input ) and (randomly generated) row and column location Assign Q to (known row and column location ) and 0 to all others location Please show compile script working as well
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT