python - savWriter writerows with Dataframe -


i trying use savreaderwriter library python. have dataframe read in via df = pd.read_csv. using following piece of code won't seem write rows file.

with savreaderwriter.savwriter(savfilename, *args) writer: writer.writerows(df) 

i getting following error typeerror: 'str' object not support item assignment.any appreciated.

this sample on https://pythonhosted.org/savreaderwriter/

savfilename = 'somefile.sav' records = [[b'test1', 1, 1], [b'test2', 2, 1]] varnames = ['var1', 'v2', 'v3'] vartypes = {'var1': 5, 'v2': 0, 'v3': 0} savreaderwriter.savwriter(savfilename, varnames, vartypes) writer:     record in records:         writer.writerow(record) 

i think can divide dataframe 3 fields(records, varnames, vartypes) way, can use method in pandas write data file.

import pandas pd  sensor_values = pd.dataframe([[1,'aaa','bbb'],[2,'ppp','xxx']], columns=['a','b','c'])  varnames=sensor_values.columns records = sensor_values.values vartype = {key: 0 x, key in enumerate(sensor_values.columns)} 

Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -