Reputation: 53
I'm trying to import data from a .csv
file and then export it to another .csv
file. in the file I wanted to export to, there were already existing data in the same column I wanted to write. So I used the startrow=
method to start exporting my data from the appropriate row. but as I ran the code, it raised the error
TypeError: to_csv() got an unexpected keyword argument 'startrow'
Here's the code
import pandas as pd
def mokacsv(file_name):
importing = pd.read_csv(file_name)
column_netsales = importing['Net Sales']
sum_of_netsales = (column_netsales)
sum_of_netsales.to_csv('example1.csv', index=False, header=True, startrow=30)
print(mokacsv(r"example2.csv"))
Any help is greatly appreciated, P.S this is about my second-week coding python3, I have no prior experience.
Upvotes: 0
Views: 1466
Reputation: 550
Try using the concat
function
import pandas as pd
one = pd.DataFrame({
'Name': ['Alex', 'Amy', 'Allen', 'Alice', 'Ayoung'],
'subject_id':['sub1','sub2','sub4','sub6','sub5'],
'Marks_scored':[98,90,87,69,78]},
index=[1,2,3,4,5])
two = pd.DataFrame({
'Name': ['Billy', 'Brian', 'Bran', 'Bryce', 'Betty'],
'subject_id':['sub2','sub4','sub3','sub6','sub5'],
'Marks_scored':[89,80,79,97,88]},
index=[1,2,3,4,5])
print pd.concat([one,two])
Output:
More at Python Pandas - Concatenation and Python + Pandas: Add value to specific row in csv-file
Upvotes: 1