Skip to main content
added 1 character in body
Source Link

If both columns are strings, you can concatenate them directly:

df["period"] = df["Year"] + df["quarter"] 

If one (or both) of the columns are not string typed, you should convert it (them) first,

df["period"] = df["Year"].astype(str) + df["quarter"] 

###Beware of NaNs when doing this!

Beware of NaNs when doing this!


If you need to join multiple string columns, you can use agg:

df['period'] = df[['Year', 'quarter', ...]].agg('-'.join, axis=1) 

Where "-" is the separator.

If both columns are strings, you can concatenate them directly:

df["period"] = df["Year"] + df["quarter"] 

If one (or both) of the columns are not string typed, you should convert it (them) first,

df["period"] = df["Year"].astype(str) + df["quarter"] 

###Beware of NaNs when doing this!


If you need to join multiple string columns, you can use agg:

df['period'] = df[['Year', 'quarter', ...]].agg('-'.join, axis=1) 

Where "-" is the separator.

If both columns are strings, you can concatenate them directly:

df["period"] = df["Year"] + df["quarter"] 

If one (or both) of the columns are not string typed, you should convert it (them) first,

df["period"] = df["Year"].astype(str) + df["quarter"] 

Beware of NaNs when doing this!


If you need to join multiple string columns, you can use agg:

df['period'] = df[['Year', 'quarter', ...]].agg('-'.join, axis=1) 

Where "-" is the separator.

edited body
Source Link
Alex Waygood
  • 7.8k
  • 3
  • 31
  • 50

ifIf both columns are strings, you can concatenate them directly:

df["period"] = df["Year"] + df["quarter"] 

If one (or both) of the columns are not string typed, you should convert it (them) first,

df["period"] = df["Year"].astype(str) + df["quarter"] 

###Beware of NaNs when doing this!


If you need to join multiple string columns, you can use agg:

df['period'] = df[['Year', 'quarter', ...]].agg('-'.join, axis=1) 

Where "-" is the separator.

if both columns are strings, you can concatenate them directly:

df["period"] = df["Year"] + df["quarter"] 

If one (or both) of the columns are not string typed, you should convert it (them) first,

df["period"] = df["Year"].astype(str) + df["quarter"] 

###Beware of NaNs when doing this!


If you need to join multiple string columns, you can use agg:

df['period'] = df[['Year', 'quarter', ...]].agg('-'.join, axis=1) 

Where "-" is the separator.

If both columns are strings, you can concatenate them directly:

df["period"] = df["Year"] + df["quarter"] 

If one (or both) of the columns are not string typed, you should convert it (them) first,

df["period"] = df["Year"].astype(str) + df["quarter"] 

###Beware of NaNs when doing this!


If you need to join multiple string columns, you can use agg:

df['period'] = df[['Year', 'quarter', ...]].agg('-'.join, axis=1) 

Where "-" is the separator.

added 344 characters in body
Source Link
cs95
  • 406.2k
  • 106
  • 744
  • 797

if both columns are strings, you can concatenate them directly:

dataframe["period"]df["period"] = dataframe["Year"]df["Year"] + df["quarter"] 

If one (or both) of the columns are not string typed, you should convert it (them) first,

df["period"] = df["Year"].mapastype(str) + dataframe["quarter"]df["quarter"] 

###Beware of NaNs when doing this!


If you need to join multiple string columns, you can use agg:

df['period'] = df[['Year', 'quarter', ...]].agg('-'.join, axis=1) 

Where "-" is the separator.

dataframe["period"] = dataframe["Year"].map(str) + dataframe["quarter"] 

if both columns are strings, you can concatenate them directly:

df["period"] = df["Year"] + df["quarter"] 

If one (or both) of the columns are not string typed, you should convert it (them) first,

df["period"] = df["Year"].astype(str) + df["quarter"] 

###Beware of NaNs when doing this!


If you need to join multiple string columns, you can use agg:

df['period'] = df[['Year', 'quarter', ...]].agg('-'.join, axis=1) 

Where "-" is the separator.

Source Link
silvado
  • 18.3k
  • 2
  • 34
  • 48
Loading