Python Unique DF in loop [closed]

2024/7/5 11:18:44

I am currently writing web scraping code to scrape the PGA Tour website. I have provided a sample of a loop I am using. I would like to create a unique dataframe for every iteration through j. In the end I will have several hundred dataframes. I would like the dataframes to be listed as df1, df2, df3,...

I would then like to export all of the dataframes as a csv.

Thanks!

for j in range(0, 500):for k in range(1,9):try:print(j)df1 = url_base_1 + str(j) + url_base_2df2 = make_dataframe(df1.format(year), int(k))print(k)except:pass
Answer

If you need to upload into csv files separately during that iteration then below code follows, If this is what your looking or else please review your question

for j in range(0, 500):for k in range(1,9):try:file_name = 'Result_'+str(i)+'_'+str(j)+'.csv'df1 = url_base_1 + str(j) + url_base_2df2 = make_dataframe(df1.format(year), int(k))print(k)df2.to_csv(file_name,encoding='utf-8', index=False)except:pass

The output files will be in this format Result_0_1.csv, Result_0_2.csv and so on.

https://en.xdnf.cn/q/120242.html

Related Q&A

TypeError: unsupported operand type(s) for +=: NoneType and str

I am new to Python and Im sure that Im doing something wrong - I would like to ask a user for three numbers and print their sum, heres my current code:for i in range(0, 3):total = Nonenum = input(Pleas…

multiply list of ndarrays by list

I want to multiply a list of numbers, by a ndarray, that is, each number in the list multiply by the first ndarray. This is the list: list1 = [840,845,897]This is the list of ndarray list = df[Example]…

Python skipping last element in while iterating a list using for loop [duplicate]

This question already has answers here:Strange result when removing item from a list while iterating over it in Python(12 answers)Closed 9 years ago.class Sample:def __init__(self):self.lst_report_foot…

can this code be shortened or improved? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.This question does not appear to be about programming within the scope defined in the help center.Cl…

Count Running and Stopped Ec2 Instances with AWS Lambda

How can I count number of running and stopped EC2 instances in a particular region using boto3 and an AWS Lambda function?

Python2.7: How to split a column into multiple column based on special strings like this?

Im a newbie for programming and python, so I would appreciate your advice!I have a dataframe like this.In info column, there are 7 different categories: activities, locations, groups, skills, sights, t…

python - return and print does not give same result

what Im trying to do is take the entered string separated by commas and change it to list then for each list as a key print the associated value.def main():myDict = {a:1, b:2, c:3, d:4, e:5....}u_input…

Creating a menuBar in a frame?

import Tkinter as tk from Tkinter import Label, StringVar, Entry, Button, Menu, Frame, Tk, Canvas import subprocess from Tkconstants import LEFT, CENTER,W, SUNKEN , X, Yclass SampleApp(tk.Tk):def __ini…

Python return dictionary [closed]

Closed. This question needs debugging details. It is not currently accepting answers.Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to repro…

Use selenium and python to move mouse outside of web page area

I need to test the exit intent form on this page: https://www.graphicproducts.com/guides/5s-system/When the mouse pointer is moved outside of the web page area a popup window appears. I then need to en…