0

I have a Dataframe of about 142264 rows:

sample:

              DateAndTime  TAGID  TagValue  UIB
  2017-04-26 00:00:00.000    100       0.9  NaN
  2017-04-26 00:00:00.000    101     430.3  NaN
  2017-04-26 00:00:00.000    102     112.7  NaN
  2017-04-26 00:00:00.000    103      50.0  NaN
  2017-04-26 00:00:00.000    104     249.4  NaN
  2017-04-26 00:00:00.000    105     109.9  NaN
  2017-04-26 00:00:00.000    106     248.4  NaN
  2017-04-26 00:00:00.000    107     131.5  NaN
  2017-04-26 00:00:00.000    108     247.7  NaN
  2017-04-26 00:00:00.000    109      96.8  NaN
  2017-04-26 00:00:00.000    113     481.4  NaN
  2017-04-26 00:00:00.000    114     243.9  NaN
  2017-04-26 00:00:00.000    115    -416.0  NaN
  2017-04-26 00:00:00.000    116      -0.5  NaN
  2017-04-26 00:00:00.000    117     429.2  NaN
  2017-04-26 00:00:00.000    118     646.4  NaN
  2017-04-26 00:00:00.000    119      49.5  NaN
  2017-04-26 00:00:00.000    120     248.2  NaN
  2017-04-26 00:01:00.000    100       0.9  NaN
  2017-04-26 00:01:00.000    101     429.7  NaN
  2017-04-26 00:01:00.000    102     120.0  NaN
  2017-04-26 00:01:00.000    103      49.9  NaN
  2017-04-26 00:01:00.000    104     249.2  NaN
  2017-04-26 00:01:00.000    105     123.8  NaN
  2017-04-26 00:01:00.000    106     248.3  NaN
  2017-04-26 00:01:00.000    107     136.3  NaN
  2017-04-26 00:01:00.000    108     247.4  NaN
  2017-04-26 00:01:00.000    109      99.9  NaN
  2017-04-26 00:01:00.000    113     481.4  NaN
  2017-04-26 00:01:00.000    114     243.9  NaN

I want to filter dataframe on unique tagid and store new dataframes individually.

I tried:

data = read_json("json_tagid_100_120.json")
tagid101 = data[data["TAGID"] == 101]
print tagid101

By doing this, i am only able to store the data of Tagid 101.

but I want to store the data of individual tagid's in a new dataframe.

Dheeraj
  • 1,102
  • 3
  • 14
  • 29

1 Answers1

1

I think best is create dict of all DataFrames by convert DataFrameGroupBy object to tuple and then to dict:

dfs = dict(tuple(data.groupby("TAGID")))

print (dfs[101])
           DateAndTime  TAGID  TagValue  UIB
1  2017-04-26 00:00:00    101     430.3  NaN
19 2017-04-26 00:01:00    101     429.7  NaN
jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252
  • can i use for loop for storing the new dataframes? like: tags = data['TAGID'].unique() and then using for loop. – Dheeraj May 24 '17 at 07:52
  • Do you think `df101, df102` ... ? If yes, it is possible in python, but complicated. Check [this](https://stackoverflow.com/q/1373164/2901002) – jezrael May 24 '17 at 07:56
  • Thanks a lot. This really helped. – Dheeraj May 24 '17 at 08:06
  • can you look at this? https://stackoverflow.com/questions/44388107/date-format-changes-to-time-only-while-converting-dataframe-to-csv?noredirect=1#comment75775785_44388107 – Dheeraj Jun 06 '17 at 11:15
  • Can you please give this a look? https://stackoverflow.com/questions/44984707/pandas-resample-issue-group-data-by-hours – Dheeraj Jul 08 '17 at 09:43