1

I've looked through StackOverflow and found a related question about a script that reads an excel file, read the row from excel, then write the row to Smartsheet.

I am getting an error where the 'pd' is not defined when I run the script to read an Excel file.

Does anyone know where the 'pd' id defined? I couldn't find it. Is there another way to do this?

RUN

pi@cenicapi:~/Documents/tscripts $ ./sample.s
Traceback (most recent call last):
File "./sample.s", line 16, in
data = pd.read_csv(r'Sample.xlsx')
NameError: name 'pd' is not defined
pi@cenicapi:~/Documents/tscripts $

SCRIPT CODE:

#!/usr/bin/python3.7

import logging
import csv
import os

# Log all calls
logging.basicConfig(filename='rwsheet.log', level=logging.INFO)

from simple_smartsheet import Smartsheet
from simple_smartsheet.models import Sheet, Column, Row, Cell, ColumnType

data = **pd**.read_csv(r'Sample.xlsx')
df = **pd**.DataFrame(data, columns=[ 'ccc_key_id', 'MyDate', 'CCD', 'Max In Only', 'Max Out Only', 'avg_bits_out_min'])

example = df.values.tolist()
print(example)

Appreciate any help

Dishin H Goyani
  • 7,195
  • 3
  • 26
  • 37

1 Answers1

1

Most likely, pd is referring to the pandas module (https://pandas.pydata.org/). A lot of people abbreviate pandas as pd, and I myself use that very same one!

Problem should be solved with a simple

import pandas as pd

at the very beginning, right after import os should work. Although you will want to make sure pandas is installed in your environment!

David Buck
  • 3,752
  • 35
  • 31
  • 35