I am reading and writing a csv file using pandas.
I am reading a csv file column by column and writing it to a seperate csv file by column by column reading works fine but while writing a csv file it thorws error
import pandas
f1 = open('artist_links','a')
data_df = pandas.read_csv('upc1.upcs_result.csv')
#data_wr = pandas.to_csv('test.csv')
df = data_df['one']
dd = data_df['two']
header = ["df", "dd"]
df.to_csv("test.csv",columns = header)
Output:
Traceback (most recent call last):
File "merge.py", line 9, in <module>
df.to_csv("test.csv",columns = header)
TypeError: to_csv() got an unexpected keyword argument 'columns'
But there is a column argument actully here pandas library
How could i make this program work(Writing column by column)
Changes in v0.16.0
http://pandas.pydata.org/pandas-docs/dev/whatsnew.html
cols as the keyword for the csv and Excel writers was replaced with columns.
Try cols instead or upgrade pandas.
Instead of:
Use:
Edit: Either way you should upgrade. Sincerely. If the error is a keyword argument and you are basing your method off of documentation for the most recent version on software written over 1.5 years ago, with substantial changes made since then, you should upgrade.
EDIT2: If you're desperate to make life difficult for yourself and continue using outdated functions and try to use new features, you could do workarounds. This is not recommended, since some stuff may be a lot more subtle and throw exceptions when you least expect it.
You could... do...
EDIT3: Much simpler, but you could also do: