Reputation: 3577
I have a csv file that I am just pivoting using pandas and then trying to save as a csv. I have never had a problem doing this before, and it is pretty simple so I have no idea whats happening. One thing that I did change is I am using Anaconda and before I used the 64 bit version and now I switched to 32 bit, but I can't imagine this should be the issue...the code executes but no file is saved.
This is the full code I am using:
import pandas as pd
#read file
df=pd.read_csv(r'D:\Sheyenne\mcleod_prcp_orig.csv')
df=df.convert_objects(convert_numeric=True)
df=df[(df.Year >= 1984) & (df.Year <= 2012)]
#pivot table
prcp=pd.pivot_table(df, values='PrcpIn',
index=['Year', 'Month'],
columns='Day')
prcp.to_csv=(r'C:\Users\Stefano\Documents\Documents\2015 Summer RA\nan_count.csv')
Upvotes: 2
Views: 6815
Reputation: 2807
You have to remove "=" from your last line
write
prcp.to_csv(r'C:\Users\Stefano\Documents\Documents\2015 Summer RA\nan_count.csv')
instead of
prcp.to_csv=(r'C:\Users\Stefano\Documents\Documents\2015 Summer RA\nan_count.csv')
The latter binds the to_csv
attribute of prcp
to the string path of the csv (i.e., it's equivalent to prcp.to_csv = r'C:\Users...'
)
Upvotes: 6