I am trying to find a way to read just one value from a big dataframe in Python. I have 2 data tables in my project.
One looks like this:
Company ID Company 201512 201511 ... 199402 199401
1234 abc 1.1 0.8 ... 2.1 -0.9
.
.
.
4321 cba 2.1 -0.4 ... 0.3 -0.1
There are about 260 months and 10,000 companies. I need to check their monthly returns one by one and see if there are 36 valid data points behind that data point. That means there is no "0" or "NaN". If there are 36 valid data points, I need to run a regression of these 36 data points against 7 factors, which are listed in another table.
The other table looks like this:
Month Factor1 Factor2 ... Factor6 Factor7
201512 -0.4 1.1 ... 2.1 1.2
.
.
.
199401 0.1 0.2 ... 0.3 0.4
Now my problem is, I couldn't find a way to load just one value at a time from table 1 and create a loop for it. Can someone please advise?
0not a valid monthly return?value = df['some_field'].iloc[the_index]but you perhaps don't want that in aforloop if there's a way togroup_by.aggregate()in some way and take a specific value.