AttributeError: 'DataFrame' object has no attribute 'to_CSV' [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 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)

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.

How to fix 'tuple' object has no attribute 'open'? [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 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

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.

What is wrong with the following with this tuple [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 have the following list of tuples in Python.
CHECKS = [
('Standard JavaScript Inlining Optimization', ('EMBED_JAVASCRIPT',), 'check_js_inlining'),
('HTML5 Advanced Cache', ('JAVASCRIPT_HTML5_CACHE', 'CSS_HTML5_CACHE'), 'check_html5_advanced_cache'),
('Cookieless Resource Domain', ('RENAME_JAVASCRIPT', 'RENAME_CSS'), 'check_cookieless_resource_domain'),
('Minificatiopn of JS', ('MINIFY_JAVASCRIPT',), 'check_js_minifaction'),
('File Versioning', ('RENAME_JAVASCRIPT', 'RENAME_IMAGE', 'RENAME_CSS'), 'check_file_versioning'),
('Small Image Embedding', ('EMBED_IMAGE',), 'check_small_image_embedding'),
('Responsive Image Loading', ('RESPONSIVE_IMAGES',), 'check_responsive_image_loading')
('Asynchronous JS and CSS Loading', ('ASYNC_JAVASCRIPT',), 'check_async_js_and_css_loading'),
('JS Pre-Execution', ('PRE_EXECUTE_JAVASCRIPT',), 'check_js_pre_execution'),
]
Upon execution it throws the error
File "FEO_processor.py", line 14, in FEOProcessor
('Asynchronous JS and CSS Loading', ('ASYNC_JAVASCRIPT',), 'check_async_js_and_css_loading'),
TypeError: 'tuple' object is not callable
What am I missing here.
You are missing a comma:
('...', ('RESPONSIVE_IMAGES',), 'check_responsive_image_loading')
↑ HERE

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