SyntaxError on filename when trying to read file? [closed] - python

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
I am trying to use machine learning to predict students' future grade, but am stuck at the beginning.
Seems like pandas.read_csv cannot read psv file, I got:
df = pd.read_csv(‘training.psv’)
^
SyntaxError: invalid character in identifier
How can I read psv file through python?

The problem is in the quotes symbol. You should either use ' or ".
Try:
df = pd.read_csv('training.psv')

pd.read_csv("training.psv", sep = "|", header = FALSE, stringsAsFactors = FALSE)
That should work

Related

Python - invalid character in identifier error [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I have this code in a file called script.py
import json
myjson=json.loads(open(‘id.json’,’rb’))
[(os.makedirs(os.path.join(*v.split(‘_’))), open(os.path.join(*v.split(‘_’),‘id.txt’),’w’).write(k)) for k,v in myjson.items()]
I also have in the same folder, a file called id.json that looks like this:
{
"0":"text_test",
"1":"text_text",
"2":"test_test",
...
}
But when I try to run py script.py command on the cmd, I get this error :
File "script.py", line 2
myjson=json.loads(open(‘id.json’,’rb’))
^
SyntaxError: invalid character in identifier
I am not very familiar with Python and some guides from the web didn't help me out.
The quote you are using is invalid.
You are using: ‘
You have to use: " or '
Replace all of your ‘ with '

replace a char in string within triple ticks in python [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
I have the following code :
Integration_Minute = 00
Integration_Schedule = '''{"cluster":{"scheduling":{"shutdownHours":{"isEnabled":true,"timeWindows":["Sat:00:00-Mon:04:xx","Tue:00:00-Tue:04:xx","Wed:00:00-Wed:04:xx","Thu:00:00-Thu:04:xx","Fri:00:00-Fri:04:xx"]}}}}'''
print(Integration_Schedule.replace("xx", Integration_Minute))
I want to replace xx with 00 but this doesnt work. Whats the best way of doing this in python ?
The error I get is :
File "s.py", line 4, in <module>
print(Integration_Schedule.replace("xx", Integration_Minute))
TypeError: expected a character buffer object
Integration_Minute = '00'
>>> print(Integration_Schedule.replace("xx", Integration_Minute))
{"cluster":{"scheduling":{"shutdownHours":{"isEnabled":true,"timeWindows":["Sat:
00:00-Mon:04:00","Tue:00:00-Tue:04:00","Wed:00:00-Wed:04:00","Thu:00:00-Thu:04:0
0","Fri:00:00-Fri:04:00"]}}}}

Python Code. What is wrong with this basic code? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
Just doing some basic code and then this error popped up. I have no idea what I should fix everything seems fine. (Using Python)
Code:
dict = {'name':'Bob','ref':'Python','sys':'Win'}
print('\nReference:',dict['ref'])
print('n\Keys:',dict.keys()
del dict[ 'name' ]
dict['user']='Tom'
print('\nDictionary:',dict)
print('\nIs There A name Key?:','name' in dict)
C:\Python>dictionary.py
File "C:\Python\dictionary.py", line 4
del dict[ 'name' ]
^
SyntaxError: invalid syntaxer code here
You are missing a parenthesis on line 3. It should be:
print('n\Keys:',dict.keys())

How to fix "unexpected indent" error on a python column that isn't indented [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
My terminal is producing the error "unexpected indent" at the start of my for loop, when it is not indented at all in my editor. How can I fix this? See code below:
wb = openpyxl.load_workbook(filename = 'BE110FinalProject.xlsx')
type(wb)
sheet = wb.get_sheet_by_name('Sheet1')
for row in sheet.iter_rows('K{}:K{}'.format(258,sheet.max_row)):
for cell in row:
if (cell.value):
numerator = float(cell.value.split(':')[1])
denominator = float(cell.value.split(':')[0])
japanOutput.write(numerator + '/' + denominator + '\n')
else:
japanOutput.write('\n')
You most likely have spaces instead of tabs.
Python tends to be picky when it comes to tabs and spaces.
One thing to try would be removing your indentations and making sure you use tabs.
I hope this helped!

python says variable name is a syntax error [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
Every time I try to run these first 2 lines in python, it says:
SyntaxError: invalid syntax
And highlights the name of the variable I'm trying to define (Yname).
These are the lines I'm trying to run:
print("Hello what's your name?")\
Yname = input("your name:")
It is because of the \ at the end of the first line.
in Python \ is the line continuation character. Python is trying to parse this as
print("Hello what's your name?")Yname = input("your name:")

Categories