0

I'm new to python so please give me some slack!

I am trying to split a data frame into smaller ones based on a unique row value.

I've done this via this code:

Station2 =  df.loc[(df["Station"] == "STN002")]
Station2

I'm trying to make dataframes for each station (STN004, STN 006, ... STN184, STN198, etc.)

I know I could do this by hand and set each variable individually, but is there a way to make a function/loop to do this automatically? Just want to understand python better.

the function would have to do something like this:

StationX = df.loc[df["Station"] == "STNX")]
#where it loops through the df to name specific dataframes based on the station ID?

Thank you for the help!

S

  • for context: ibb.co/tDMCzZK -- what I want it to do (create data frame based on unique value in 'Station' column, code is different but output is the same as above. ibb.co/R7TgZwq -- example of the base data frame , 'station' column out of frame, but you can see the different stations (STN004, STN006, STN012, etc). – skinkleton Nov 16 '22 at 17:17

0 Answers0