0

I am trying to create class( requirement is to create a class) that will be able to read data from a csv file, manipulate that data and generate a new csv or excel file. Here is my code:

import pandas as pd
import numpy as np

class Probability:
    def __init__(self, path, file_name):
        self.path = path
        self.file_name = file_name
        
    def display(self):
        data_df = pd.read_csv(self.path + self.file_name)
        
    def df1(self):
        table = pd.pivot_table(data = data_df, index= ['ln'], aggfunc={'p_m':np.sum,'p_c':np.sum})
        return table
    
    def generate(self):
        writer = pd.Excelwriter('Probability.xlsx', engine = 'xlsxwriter')
        df1.self = df1.to_excel(writer, sheet_name='Probability1')

However when I am trying to run this:

pool=Probability("C:\Users\xxx\Desktop\Python\", "data.csv")

Python shows an error pointing on data.csv :

pool=Probability("C:\Users\xxx\Desktop\Python\", "data.csv")
                                             ^
SyntaxError: invalid syntax
DeepSpace
  • 78,697
  • 11
  • 109
  • 154
Camilla
  • 31
  • 3
  • add r to before your paths r'C:\....' – CogNitive Apr 15 '21 at 18:08
  • @DeepSpace not a good choice for a duplicate. OP never uses raw strings. The error happens because the backslash escapes the quotation mark that was supposed to mark the string end – Pranav Hosangadi Apr 15 '21 at 18:53
  • @PranavHosangadi The problem is exactly the same, regardless if the string is raw or not. Neither string can end in a backslash. They both generate `SyntaxError: EOL while scanning string literal` and cases are solved the same way – DeepSpace Apr 15 '21 at 18:54

0 Answers0