How to fix 'tuple' object has no attribute 'open'? [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 4 months ago.
Improve this question
Im parsing data for study purposes so I create scraping module, data frame module and now I need to finish "upload to Google Drive data frame as Google Sheet" but stuck on this error.
from fileinput import filename
import gspread
credentials = {...
}
gc = gspread.oauth_from_dict(credentials)
tag = bs_search
sh = gc.open(filename, 'kid')
worksheet = sh.add_worksheet(title = tag, rows=100, cols=20)
worksheet.update([df.columns.values.tolist()] + df.values.tolist())
worksheet.update_cell(1, 4, 'Send to')
worksheet.update_cell(1, 5, 'Not Send to')
worksheet.update_cell(1, 6, 'Instagram')
Output:
13 gc = gspread.oauth_from_dict(credentials)
15 tag = bs_search
---> 16 sh = gc.open(filename, 'kid')
17 worksheet = sh.add_worksheet(title = tag, rows=100, cols=20)
18 worksheet.update([df.columns.values.tolist()] + df.values.tolist())
AttributeError: 'tuple' object has no attribute 'open'

If you look at the docs for the gspread project, they have an example for this function:
gc, authorized_user = gspread.oauth_from_dict(credentials)
Notice there are two values before the equals.
More information: https://docs.gspread.org/en/latest/oauth2.html

Related

New to Python - Trying to output a dataframe to csv from Input [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 25 days ago.
Improve this question
Good Morning/ Afternoon
I'm relatively new, learning some python for the finance It world.
Trying to figure out some inputs > outputs for data.
My goal is to create a CSV from the ticket input
only thing missing is it won't create a new file from said "ticker"
import yfinance as yf
start_date = '2020-01-01'
end_date = '2023-01-20'
ticker = input("Enter Ticker :")
data = yf.download(ticker, start_date, end_date)
print(data.tail())
# Export data to a CSV file
data.to_csv = ( '.csv')
As Matt said, you should use:
data.to_csv("name_of_file.csv")
If you wish your code to have variable csv name:
input_name = "IBM"
data.to_csv(f"{input_name}.csv")
You need to define input_name though.

AttributeError: 'DataFrame' object has no attribute 'to_CSV' [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'm trying to store my extracted chrome data into a csv format using df.to_CSV
here is my code :
content = driver.page_source
soup = BeautifulSoup(content)
for a in soup.findAll('a',href=True, attrs={'class':'_13oc-S'}):
name=a.find('div', attrs={'class':'_4rR01T'})
price=a.find('div', attrs={'class':'_30jeq3 _1_WHN1'})
rating=a.find('div', attrs={'class':'hGSR34 _2beYZw'})
products.append(name.text)
prices.append(price.text)
ratings.append(rating.text)
df = pd.DataFrame({'Product Name':products, 'Price':prices, 'Rating':ratings})
df.to_CSV(r'C:\Users\Krea\Documents\products.csv', index=False)
It's case-sensitive, should be df.to_csv(...)
Python is case sensitive. Change the last row to:
df.to_csv(r'C:\Users\Krea\Documents\products.csv', index=False)

python Flask, TypeError: 'NoneType' object is not subscriptable [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'm studying Flask very recently and trying to create API.
However, when It request json data, this error occurs.
if content['words'] is not None:
TypeError: 'NoneType' object is not subscriptable
could anyone can help this?
Thanks
my code is below:
#app.route("/process",methods=['GET', 'POST'])
def process():
content = request.json
words = {}
if content['words'] is not None:
for data in content['words'].values():
words[data['word']] = data['weight']
process_from_text(content['text'], content['maxCount'], content['minLength'], words)
result = {'result':True}
return jsonify(result
The problem is most likely that request is not a valid json request. If that is the case then content will be equal to None which means it is not subscriptable.

Invalid syntax error in an `if` statement which I am unable to understand? [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
I went line by line and came up to this error.
SyntaxError: invalid syntax
In, the emailRegex gets highlighted
if cell.value and isinstance(cell.value, str) emailRegex.match(cell.value):
The complete code(python3.x)
import re, openpyxl, os, sys
def sort_email_from_xl():
loc = input("Please enter path of the file:")
os.chdir(loc)
file = input("Filename:")
wb = openpyxl.load_workbook(file, use_iterators=True)
sheet = input("Which Sheet do you want to email?\n")
return sheet
wb.get_sheet_by_name(sheet)
ws = wb.get_sheet_by_name(sheet)
emailRegex = re.compile(r".*?([a-zA-Z0-9\._%+\-]+#[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,4}).*?")
customeremails = [] #works fine till here in idle
for row in ws.iter_rows():
for cell in row:
if cell.value and isinstance(cell.value, str) emailRegex.match(cell.value):
mail = emailRegex.match(cell.value)
if mail:
mail = mail.group(0) # use parentheses to call the function
cell.text = mail
customeremails.append(mail)
print(customeremails)
Can someone point to a resource where I can read what exactly is going wrong? I have been trying to sort this function out for almost 12 hours now, with help from SO and reading through docs.
Is the code fine after current error?
Thanks
You missed and between predicates:
if cell.value and isinstance(cell.value, str) and emailRegex.match(cell.value):
^^^

Detail AttributeError: 'module' object has no attribute 'workbook' [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
I keep getting the Detail AttributeError: 'module' object has no attribute 'workbook' error.
below is my code
import xlwt
workbook = xlwt.workbook()
sheet = workbook.add_sheet('Eswar')
sheet.write (4,4,'Test passed')
workbook.save("D:\resultsLatest.xls")
what have i done wrong?
I am using python 2.7
In source code on github you can see right spelling Workbook. Your code should be:
import xlwt
workbook = xlwt.Workbook()
sheet = workbook.add_sheet('Eswar')
sheet.write(4,4,'Test passed')
workbook.save("D:\\resultsLatest.xls")

Categories