Python Forum
Increase the speed of a python loop over a pandas dataframe
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Increase the speed of a python loop over a pandas dataframe
#1
Hi
I´m using the following code to fill a dataframe with values that are stored in a .nc file

This code is quite slow. The speed can be improved with list comprehensions? If the answer is yes, can you give me an example?
Thank you very much


data_range = pd.date_range(start = '2000-01-01', end = '2011-01-01', freq='H')

df1 = pd.DataFrame(0, columns = ['t2m'], index = data_range)
df = df1.iloc[:-1 , :]

dt = np.arange(0, data.variables['time'].size)

temperature = data.variables['t2m']

for time_index in dt:
    df.iloc[time_index] = temperature[time_index, min_index_lat,min_index_lon]-273.15
    print (time_index)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python Alteryx QS-Passing pandas dataframe column inside SQL query where condition sanky1990 0 723 Dec-04-2023, 09:48 PM
Last Post: sanky1990
  Question on pandas.dataframe merging two colums shomikc 4 814 Jun-29-2023, 11:30 AM
Last Post: snippsat
  Pandas AttributeError: 'DataFrame' object has no attribute 'concat' Sameer33 5 5,554 Feb-17-2023, 06:01 PM
Last Post: Sameer33
  help how to get size of pandas dataframe into MB\GB mg24 1 2,332 Jan-28-2023, 01:23 PM
Last Post: snippsat
  pandas dataframe into csv .... exponent issue mg24 10 1,761 Jan-20-2023, 08:15 PM
Last Post: deanhystad
  How to assign a value to pandas dataframe column rows based on a condition klllmmm 0 823 Sep-08-2022, 06:32 AM
Last Post: klllmmm
  How to retrieve records in a DataFrame (Python/Pandas) that contains leading or trail mmunozjr 3 1,741 Sep-05-2022, 11:56 AM
Last Post: Pedroski55
  export into excel, how to implement pandas into for-loop deneme2 6 2,431 Sep-01-2022, 05:44 AM
Last Post: deneme2
  "Vlookup" in pandas dataframe doug2019 3 1,844 May-09-2022, 01:35 PM
Last Post: snippsat
Question How can I merge several images via loop using the information of a dataframe? noahverner1995 1 1,423 Dec-31-2021, 05:03 AM
Last Post: noahverner1995

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020