File size: 623 Bytes
9f4d625
 
1a5d7bd
9f4d625
1a5d7bd
9f4d625
 
1a5d7bd
9f4d625
 
1a5d7bd
9f4d625
 
1a5d7bd
 
 
 
 
 
9f4d625
 
 
9d0f8b1
9f4d625
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import pandas as pd

def preprocess_csv(data):
  """
  Preprocesses CSV data and returns a single string.

  Args:
    data: Either a DataFrame containing CSV data or a file path to a CSV file.

  Returns:
    A string containing the preprocessed text.
  """

  if isinstance(data, pd.DataFrame):
    # Process DataFrame directly
    df = data
  else:
    # Read CSV from file path
    df = pd.read_csv(data)

  # Preprocess the data (replace with your specific logic)
  # Example: Combine relevant columns into a single string
  text = " ".join(str(word) for col in df.columns for word in df[col].tolist())

  return text