Question

How can I use Python with Pandas to create a new.csv file with the headers "c1,...

How can I use Python with Pandas to create a new.csv file with the headers "c1, c2, c3, c4, c5, c6" and the first line of data "8, 5, -9, 7, 2.1, 1.7" from the original.csv file?

Homework Answers

Answer #1
import pandas as pd

#reading csv file
data=pd.read_csv('original.csv')

#creating headers
headers=['c1','c2','c3','c4','c5','c6']

#adding headers
data=pd.read_csv('original.csv',names=headers, header=None)

#writing data into new.csv file
data.to_csv('new.csv')

original.csv

new.csv

here 0 denotes the number of rows are 1,starting from 0

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Please Use C++ I tried to calculate complex number by using *= and operator /= but...
Please Use C++ I tried to calculate complex number by using *= and operator /= but I got an incorrect result compared with the result of complex number calculator For example, When I calculate ( (c5 *= c4) *= c4) by using my operator function, the result was 1.08288e+06+1.11262e+07i on output, However, when using a complex calculator, the result was = −253987.448 − 355181.112i, so I got the wrong answer There is my code below. It compiles well, but my...
Python: Working with CSV file --> How would I write a function that will return a...
Python: Working with CSV file --> How would I write a function that will return a list of lists, with the frequency and the zip code. Organize the list in decreasing order of frequency (Print the number of suppliers and the zip code for the 10 most common zip codes in the file. ) An example of three items from the 720 zip codes results in: [ ... [9, '65616'], [8, '94573'], [8, '63103'] ...]. This tells us that Branson,...
a toy uses circuit with capacitors to create LEDs flash more quickly. 3 capacitors C1, C2,...
a toy uses circuit with capacitors to create LEDs flash more quickly. 3 capacitors C1, C2, C3 are in series from points a to b. What can be said about equivalent capacitance Cab? C1= 5 uF C2= 7 uF C3= unknown . SELECT ALL THAT APPLY (MORE THAN ONE) Answers: 5 uF < Cab < 7uF Cab > 12 uF Cab< 5 uF Cab< C3 5 uF < Cab < 12 uF A piece of metal is in uniform E...
A student will randomly select 5 cards from a deck of 52 cards. Each card is...
A student will randomly select 5 cards from a deck of 52 cards. Each card is uniquely identified by a label which is a combination of a letter (one of the following: A, B, C, D) followed by a number (one of the following: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13). The labels on the cards are A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, B1, B2, B3, B4,...
A student will randomly select 5 cards from a deck of 52 cards. Each card is...
A student will randomly select 5 cards from a deck of 52 cards. Each card is uniquely identified by a label which is a combination of a letter (one of the following: A, B, C, D) followed by a number (one of the following: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13). The labels on the cards are A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, B1, B2, B3, B4,...
1. First, create a Pandas data frame looks as following: Name Product Amount 0 Bob apple...
1. First, create a Pandas data frame looks as following: Name Product Amount 0 Bob apple 1 1 Bob banana 2 2 jessica orange 3 3 jessica banana 4 4 jessica tomato 3 5 mary banana 2 6 john apple 3 7 john grape 1 Second, find out for each product, how many were sold (for example, 4 units of Apple were sold). Third, which products sales are larger than 3 (for example, apple sold more than 3 units) PYTHON
Use python code to solve IVP. Code must print both general and particular solutions. Please paste...
Use python code to solve IVP. Code must print both general and particular solutions. Please paste full python code for your answer. IVP: y′=(5x^2)(y^2)+(125x^2), y(−7π)=10 Below is an example of code for the problem 7x″−3x′−57x=0, x(2π)=9, x′(−π)=5exp(3) : from sympy import * y = symbols('y') x = Function('x') x = dsolve(7*diff(x(y),y,2)-3*diff(x(y),y)-57*x(y),x(y)) print('The general solution is: ',x,'.',sep='') x = x.rhs xp = diff(x,y) y0, y0p = 2*pi, -pi x0, x0p = 9, 5*exp(3) x0LHS, x0pLHS = x.subs(y,y0) - x0, xp.subs(y,y0p) -...
Use Python to Complete the following on a single text file and submit your code and...
Use Python to Complete the following on a single text file and submit your code and your output as separate documents. For each problem create the necessary list objects and write code to perform the following examples: Sum all the items in a list. Multiply all the items in a list. Get the largest number from a list. Get the smallest number from a list. Remove duplicates from a list. Check a list is empty or not. Clone or copy...
How would I solve these python problems? A) File Display Download the file from here named...
How would I solve these python problems? A) File Display Download the file from here named numbers.txt . Write a program that displays all of the numbers in the file. numbers.txt contains 22 14 -99 AB B) Error Check Float Input When you want an int input you can check the input using the string isdigit() method. However, there is no comparable check for float. Write a program that asks the user to enter a float and uses a try-except...
So, i have this code in python that i'm running. The input file is named input2.txt...
So, i have this code in python that i'm running. The input file is named input2.txt and looks like 1.8 4.5 1.1 2.1 9.8 7.6 11.32 3.2 0.5 6.5 The output2.txt is what i'm trying to achieve but when the code runs is comes up blank The output doc is created and the code doesn't error out. it should look like this Sample Program Output 70 - 510, [semester] [year] NAME: [put your name here] PROGRAMMING ASSIGN MENT #2 Enter...