'How do I save my new output data in python? [duplicate]
I started out with a labeled data set and have now changed that to number data through using MultiColumnLabelEncoder. I now want to save the new output to a CSV file. How do I go about doing that, code below and an image of the data I want to save.
class MultiColumnLabelEncoder:
def __init__(self,columns = None):
self.columns = columns # array of column names to encode
def fit(self,X,y=None):
return self # not relevant here
def transform(self,X):
'''
Transforms columns of X specified in self.columns using
LabelEncoder(). If no columns specified, transforms all
columns in X.
'''
output = X.copy()
if self.columns is not None:
for col in self.columns:
output[col] = LabelEncoder().fit_transform(output[col])
else:
for colname,col in output.iteritems():
output[colname] = LabelEncoder().fit_transform(col)
return output
def fit_transform(self,X,y=None):
return self.fit(X,y).transform(X)
MultiColumnLabelEncoder(columns = ['Title','Description']).fit_transform(data)
Solution 1:[1]
You can simply use the pandas to_csv() method. Check out this link: https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.to_csv.html
df.to_csv('filepath/filename.csv')
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Phanish Chava |

