How to remove some part from String from Pandas [duplicate] - pandas

This question already has answers here:
Extracting just Month and Year separately from Pandas Datetime column
(13 answers)
Closed last year.
I only want the Month from this Column and want to drop all the rest of the values how do I do that. Have checked all then StackOverFlow other questions nothing seems top work.
Can someone please help me out :D

This looks like a datetime object, but if not you'll want to convert it to one with:
df['created_at']= pd.to_datetime(df['created_at'])
Once it's a datetime object, you can create a month column with the following:
df['month'] = df['created_at'].dt.month

Related

Unpivot data with dynamic Date columns [duplicate]

This question already has answers here:
How do I melt a pandas dataframe?
(3 answers)
Closed 8 months ago.
I need to unpivot a dataset with the column names in date format. To un-pivot, I would need to call column names, but they would keep changing every month; hence, I cannot use column names because of their dynamic nature.
Here is an example of the table:
I need to un-pivot these date columns and I cannot call column names as these columns may change next month. Here is the desired output:
Could you please help me with any solution for this in spark SQL or Pandas as I am using Palantir foundry.
Note:
There are hundreds of rows in data, this only one row is a sample example.
If I rename column names, changing them back to date columns would be difficult as well.
Thanks.
You can use melt() to achieve this
pd.melt(df, id_vars=df.columns[:3], value_vars=df.columns[3:],
var_name='Date', value_name='Value')

MSACCESS SQL Date greater than 3 days ago - Pass Through query to Oracle [duplicate]

This question already has answers here:
Add days Oracle SQL
(6 answers)
Closed 12 months ago.
I am having an issue trying to add a portion to my WHERE clause to get only the last 3 days of data rather than grab the whole table. The date format comes through as 'dd-Mon-yy'
Here is my current WHERE clause
WHERE ("IAINVN00"."REF_LOCN" LIKE '51C%'
OR "IAINVN00"."REF_LOCN" LIKE '511%')
This works fine, just brings back way too much data. When I add:
and "IAINVN00"."ADJDATE" >= (Date()-3)
This brings back an error of "ODBC--call failed. [Oracle][ODBC][Ora]ORA-00936: missing expression (#936)"
I have tried using this as well and get the same error
DateAdd("d",-3,Date())
In order to fix this, instead of using Date, I needed to use SysDate.
and "IAINVN00"."ADJDATE" >= sysdate - 3

How to read in a number from a csv as a time in Pandas [duplicate]

This question already has answers here:
Convert number to time in Python
(3 answers)
Add Leading Zeros to Strings in Pandas Dataframe
(7 answers)
Closed 1 year ago.
I have a csv that I'm trying to parse with Pandas, and there's a column that contains a 24 hour time, but it's just a simple number in the csv:
CaseNumber
OccurDate
OccurTime
OffenseCategory
OffenseType
20-X5397620
1/1/20
345
Assault Offenses
Simple
Should I join it with OccurDate so I can do the normal datetime parsing with Pandas?
first of all, please check the "OccureTime" dataType using df.info(). for me it does not look 24H data column.
Actually I think this answer is the one I want:
Convert number to time in Python
All I'm looking for is the time, and the date part of the datetime is irrelevant for my needs.
Also this answer to help pad some of those values that are only two digits out to 4: Add Leading Zeros to Strings in Pandas Dataframe

Fetch the time between two timestamps in R [duplicate]

This question already has answers here:
Subset a dataframe between 2 dates
(8 answers)
Closed 5 years ago.
Please run the code below: The "patients$time" column gives the timestamp. I want to fetch all the records between two times say first row value "2017-01-02 11:41:53" and 226th row value "2017-08-07 09:06:07". I want to basically get all the records between these two times. I tried dbGetquery but am getting an error. Please help.
library(bupaR)
patients
Try this:
patients[patients$time > '2017-01-02 11:41:53' & patients$time < '2017-08-07 09:06:07',]

Datetiime column needs to show only the time [duplicate]

This question already has answers here:
How to get Time from DateTime format in SQL?
(19 answers)
Closed 5 years ago.
I have a datetime column that has data as this:
Appt_DateTime (datetime, not null)`
12/30/1899 7:50:00PM
I want to display only the time in this case the 7:50:pm. it can be with or without the seconds, better without them.
How can I do this in a select?
You may try this by using something like
Select cast(<your column name> as time) [time] from <your table>