data-transform

Converting columns with date in names to separate rows in Python

筅森魡賤 提交于 2021-02-11 09:41:08
问题 I already got answer to this question in R, wondering how this can be implemented in Python. Let's say we have a pandas DataFrame like this: import pandas as pd d = pd.DataFrame({'2019Q1':[1], '2019Q2':[2], '2019Q3':[3]}) which displays like this: 2019Q1 2019Q2 2019Q3 0 1 2 3 How can I transform it to looks like this: Year Quarter Value 2019 1 1 2019 2 2 2019 3 3 回答1: Using DataFrame.stack with DataFrame.pop and Series.str.split: df = d.stack().reset_index(level=1).rename(columns={0:'Value'})

Remove columns from Azure Table Storage

情到浓时终转凉″ 提交于 2020-02-07 23:43:17
问题 Here is a snippet of code I am using to read entities from Table storage: public void OnReadingEntity(object sender, ReadingWritingEntityEventArgs args) { XNamespace AtomNamespace = "http://www.w3.org/2005/Atom"; XNamespace AstoriaMetadataNamespace = "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"; GenericEntity entity = args.Entity as GenericEntity; if (entity == null) { return; } // read each property, type and value in the payload var properties = args.Entity.GetType()

Azure Table Storage - remove columns

こ雲淡風輕ζ 提交于 2020-02-04 02:17:10
问题 I think this is not possible, but however I ask the question, maybe I have missed something. Can we add/remove columns from an azure table? For example by default we get those columns: PartitionKey, RowKey, Timestamp, ETag. Can I add for example another 3: FirstName, LastName, Email columns? After that I will insert some values and I want to remove column Email and add instead column Address. Can we do this? 回答1: Azure Tables do not have "columns" as SQL tables do. Azure Tables have entities.

Converting columns with date to rows in R

耗尽温柔 提交于 2020-01-16 01:18:30
问题 Let's say we have a data.frame in R like this: d = data.frame('2019q1' = 1, '2019q2' =2, '2019q3' = 3) Which looks like this: X2019q1 X2019q2 X2019q3 1 1 2 3 How can I transform it to looks like this: Year Quarter Value 2019 1 1 2019 2 2 2019 3 3 回答1: We can gather into 'long' format and extract the components with str_extract or parse_number library(dplyr) library(tidyr) library(stringr) gather(d) %>% transmute(Year = readr::parse_number(key), Quarter = as.numeric(str_extract(key, "(?<=q)\\d

Filtering data values in one column based on another column and then inserting values into different columns in same SQL Table

倾然丶 夕夏残阳落幕 提交于 2019-12-11 02:11:14
问题 This is a bit of a conundrum I am trying to solve using SSIS and a conditional-split transformation. I have a .csv file that contains attribute data in one row for each unique user and the values for each attribute in another column. i.e.: Attribute, Attribute Type ID, 0000000001 Birthdate, 09/02/1976 Role, Manager Or something of the sort. I need to split the attributes into columns that include the Attribute Type Data. So the desired outcome would be: ID, Birthdate, Role, 0000000001, 09/02