logo
down
shadow

Pandas time series indexing -- re


Pandas time series indexing -- re

By : 李大仁
Date : November 21 2020, 12:01 PM
I hope this helps you . docs are here
This is called partial string indexing. In a nutshell, providing a string will get you results that 'match', e.g. they are included in the specified interval, while if you specify a Timestamp/datetime then its exact; it HAS to be in the index.
code :
In [4]: df = DataFrame(np.random.randn(20,2),index=date_range('20130101',periods=20,freq='H'))

In [5]: df
Out[5]: 
                            0         1
2013-01-01 00:00:00 -0.339751  1.223660
2013-01-01 01:00:00  0.525203 -0.987815
2013-01-01 02:00:00  1.724239  0.213446
2013-01-01 03:00:00 -0.074797 -1.658876
2013-01-01 04:00:00  0.483425 -2.112314
2013-01-01 05:00:00  0.094140  0.327681
2013-01-01 06:00:00 -1.265337 -0.858521
2013-01-01 07:00:00 -1.470041  0.168871
2013-01-01 08:00:00 -0.609185  0.829035
2013-01-01 09:00:00  0.047774  0.221399
2013-01-01 10:00:00  0.814162 -1.415824
2013-01-01 11:00:00  1.070209  0.720150
2013-01-01 12:00:00  0.887571 -0.611207
2013-01-01 13:00:00  1.669451 -0.022434
2013-01-01 14:00:00 -1.796565 -1.186899
2013-01-01 15:00:00  0.417758  0.082021
2013-01-01 16:00:00 -1.064019 -0.377208
2013-01-01 17:00:00  0.939902  0.430784
2013-01-01 18:00:00 -0.645667  1.611992
2013-01-01 19:00:00 -0.172148 -1.725041

[20 rows x 2 columns]

In [6]: df['20130101 7:00:01':'20130101 10:00:00']
Out[6]: 
                            0         1
2013-01-01 08:00:00 -0.609185  0.829035
2013-01-01 09:00:00  0.047774  0.221399
2013-01-01 10:00:00  0.814162 -1.415824

[3 rows x 2 columns]

In [7]: df.index
Out[7]: 
<class 'pandas.tseries.index.DatetimeIndex'>
[2013-01-01 00:00:00, ..., 2013-01-01 19:00:00]
Length: 20, Freq: H, Timezone: None
df[(df.index > Timestamp('20130101 10:00:00')) & (df.index < Timestamp('201301010 17:00:00')])


Share : facebook icon twitter icon
time series data indexing using pandas or numpy

time series data indexing using pandas or numpy


By : Peter
Date : March 29 2020, 07:55 AM
wish of those help You can do it using the relativedelta function from the dateutil library.
code :
from dateutil.relativedelta import relativedelta
start = df.index[0]
def func(item):
    delta = relativedelta(item, start)
    return (delta.years, delta.months, delta.days)

>>>> pd.DataFrame(list(df.index.map(func)),
                  index=df.index, columns=['year', 'month', 'day'])

                     year  month  day
0_1                                  
2011-11-01 09:00:00     0      0    0
2011-11-01 09:01:00     0      0    0
2011-11-01 09:02:00     0      0    0
2011-11-01 15:03:00     0      0    0
2011-11-01 15:04:00     0      0    0
2011-11-01 15:15:00     0      0    0
2011-11-02 09:00:00     0      0    1
2011-11-02 09:01:00     0      0    1
2011-11-02 09:02:00     0      0    1
2011-11-02 09:03:00     0      0    1
parallel indexing in pandas dataframe using a pandas series?

parallel indexing in pandas dataframe using a pandas series?


By : user2285334
Date : March 29 2020, 07:55 AM
hope this fix your issue You could use DataFrame.lookup, and then build a new frame. Not the prettiest, but:
code :
>>> s
a    3
b    5
c    8
d    1
Name: 0, dtype: int64
>>> df.lookup(s.values, s.keys())
array([ 3, 68, 66, 34])
>>> pd.DataFrame(dict(zip(s.keys(), df.lookup(s.values, s.keys()))), index=[0])
   a   b   c   d
0  3  68  66  34
indexing pandas series with an integer value

indexing pandas series with an integer value


By : Chris Gelles
Date : March 29 2020, 07:55 AM
I hope this helps you . Maybe better is use concat and set_index:
code :
print bulk_order_id

1    523
2    528
3    527
4    573
Name: order_id, dtype: object

print cluster_6_loc

1    Cluster 1
2    Cluster 2
3    Cluster 3
4    Cluster 4
Name: Clusters, dtype: object

cluster_final = pd.concat([bulk_order_id, cluster_6_loc], axis=1).set_index('Clusters')
#reset index name
cluster_final.index.name = ''

print cluster_final.ix[:,0]

Cluster 1    523
Cluster 2    528
Cluster 3    527
Cluster 4    573
Name: order_id, dtype: object
Indexing a series in python pandas

Indexing a series in python pandas


By : Israel Martínez
Date : March 29 2020, 07:55 AM
I hope this helps you . Below I have listed what my object countiespop returns as well as the type of the object. I cannot find a way to create a series of exclusively the 3 'STNAME'. , Is this what you are after?
code :
#create a series using the index of the current Series
pd.Series(countiespop.index)
Out[274]: 
0    California
1         Texas
2      Illinois
Name: a, dtype: object
"Indexing" a price series to a starting time point (index level = 100) with pandas data frame : P(i,t) / P(i)

"Indexing" a price series to a starting time point (index level = 100) with pandas data frame : P(i,t) / P(i)


By : Akmaral Zhakypova
Date : March 29 2020, 07:55 AM
To fix the issue you can do I have a pandas data frame, where datetime is the index of the data frame (I use t=0 for simplification, in fact there is something like 20170101 09:30:00) , Option 1
code :
df.set_index('datetime').pct_change().fillna(0) \
  .add(1).cumprod().mul(100).reset_index()

  datetime  Stock A  Stock B
0      t=0    100.0    100.0
1      t=1    120.0    150.0
2      t=2    160.0    125.0
3      t=3     80.0    100.0
def idx_me(a):
    a = np.asarray(a)
    r = np.append(1, a[1:] / a[:-1])
    return r.cumprod() * 100

df.assign(**df.drop('datetime', 1).apply(idx_me))

  datetime  Stock A  Stock B
0      t=0    100.0    100.0
1      t=1    120.0    150.0
2      t=2    160.0    125.0
3      t=3     80.0    100.0
df.assign(**df.drop('datetime', 1).pipe(
    lambda d: d.div(d.shift().bfill()).cumprod().mul(100)))

  datetime  Stock A  Stock B
0      t=0    100.0    100.0
1      t=1    120.0    150.0
2      t=2    160.0    125.0
3      t=3     80.0    100.0
Related Posts Related Posts :
  • Filtering from data
  • Where is the problem about selenium with python?
  • ansible custom filter fails when importing python library
  • How to assign the label of one column to the new one based on group maximum in pandas
  • What is the best approach for isolating a single area of similar colour?
  • Creating multiple clients for topics
  • Why is my 'for loop', despite iterating over all keys, only acting on the last one?
  • Can someone tell me what's wrong, when I run it the browsers says "This site can’t be reached"
  • Error in setting up mitmproxy on alpine 3.9
  • From traditional loop to list comprehension
  • Django celery unregistered task | relative imports
  • How to add elements in a multi dimensional array
  • Async await with sqs receive messages not working properly
  • What is definition of 'NAME' in Python grammar
  • Easy method to move rows from df to another with coditions?
  • Changing the size of only a single plot in matplotlib, without altering figure parameters
  • Fastest way to use Vision API on 10,000+ images with python
  • How to install nvidia apex on Google Colab
  • Random numbers Continuous in python
  • Fetching data after a certain time interval(10 sec) from a continuously increasing database like mysql using flask
  • Using VLOOKUP with merge in Python
  • Calculate geographical distance between 5 cities with all the possible combinations of each city
  • How to filter a pandas dataframe using multiple partial strings?
  • Pygame- make bullet shoot toward cursor direction
  • Create SEQUENCE based dictionary from list
  • How to fix broken link from Django MEDIA_ROOT?
  • How can I display the current time left in a timer in a label?
  • Compute number of occurance of each value and Sum another column in Pandas
  • How to separate the prefix in words that are 'di'?
  • Handling network errors from an external API across an application
  • Want a pandas Series of Trips Completed to count(Request) ratio for each hour as index for the given dataframe
  • Access dict keys and list elements by same index to loop over and assign values
  • Find rows from the same dataframe based on condition
  • Read only specific part first two lines from text file in python
  • Python How to convert string to dataframe?
  • How to fix this my error code program? I use Python 3.6
  • Is there a way of getting this string down to 3 words?
  • Large difference between overall F Score for a custom Spacy NER model and Individual Entity F Score
  • Drop rows where timestamps are older than subsequent row
  • Implement a bottle spin
  • Unable to convert widows epoch time to normal date time
  • Values from a XML file
  • PyAudio readframes not ending when wav file completes
  • Could not load the module
  • How to change datetime.datetime(2012, 1, 1, 0, 0) to 1/1/2012 in Python?
  • How to create ASN.1 Sequence without NamedType?
  • How to locate specific sequences of words in a sentence efficiently
  • How can I generate a multi-step process in Django without changing pages (w/out a new request)?
  • Why does this list comprehension only "sometimes" work?
  • send html report with row collapsed
  • How to define a type hint to a argument (the argument's value is a class, all expected value is a subclass of a certain
  • How do I send a styled pandas DataFrame by e-mail without losing the format?
  • How to view/average a groupby dataframe when the data is a string?
  • Django 2.2 staticfiles do not work in development
  • Flag to enable/disable numba JIT compilation?
  • Trying to split byte in a byte array into two nibbles
  • Error in Query - missing FROM-clause entry for table - SQL
  • Reading double c structures of Dll with Ctypes in Python
  • Autofill missing row in database based on missing time range
  • Get the max of a nested dictionary
  • shadow
    Privacy Policy - Terms - Contact Us © festivalmusicasacra.org