This article is brought to you by Datawrapper, a data visualization tool for creating charts, maps, and tables. Learn more.
All Blog Topics
4 min
October 23rd, 2019
![How to split and extract text from data columns in Excel & Google Sheets (1) How to split and extract text from data columns in Excel & Google Sheets (1)](https://i0.wp.com/blog.datawrapper.de/wp-content/uploads/2021/10/20210827-D81_2273-200x200.jpg)
Lisa Charlotte Muth
![How to split and extract text from data columns in Excel & Google Sheets (2) How to split and extract text from data columns in Excel & Google Sheets (2)](https://i0.wp.com/blog.datawrapper.de/wp-content/uploads/2020/08/full-181101_split-f-1024x512.png)
Sometimes, your data comes with several pieces of information in one column. Like a column with U.S. states in the formatUS-TX
. Or a column with companiesandthe product they sell:Datawrapper (Software)
.
But say you want country (US
) separate from state (TX
) — for example, to create aDatawrapper choropleth map. Good thing there are easy ways to separate data points into two or more columns.
I’ll show two ways to create multiple new columns out of one old column. We’ll useGoogle Sheets—but the same tricks should work with LibreOffice Calc, Excel, or any other spreadsheet software.
The first method is the formula=SPLIT()
:
1st method
Split columns with SPLIT()![How to split and extract text from data columns in Excel & Google Sheets (3) How to split and extract text from data columns in Excel & Google Sheets (3)](https://i0.wp.com/blog.datawrapper.de/wp-content/uploads/2020/05/181101_excel13.gif)
- Create at least two new columns next to the column whose data you want to split. To do so, click on the header (
A
,B
,C
, etc.). Then click the little triangle and select “Insert 1 right.” Repeat to create a second empty column. - In the first empty column, write
=SPLIT(B1,"-")
(or=TEXTSPLIT(B1,"-")
in Excel), withB1
being the cell you want to split and-
the character you want the cell to split on. (If you see the error#REF!
in your cell, you’ll need to create more columns.) - To apply the changes to the cells below, drag down the blue square in the bottom right of the selected cell(s). Double-click on the blue square to fill all remaining cells.
2nd method
Extract content from columns with LEFT()Sometimes you don’t have clear separator characters, but just want to extract the first or last characters of a cell. To do so, use the formulas=LEFT(B1,2)
,=RIGHT(B1,8)
, and=MID(B1,2,4)
:
![How to split and extract text from data columns in Excel & Google Sheets (4) How to split and extract text from data columns in Excel & Google Sheets (4)](https://i0.wp.com/blog.datawrapper.de/wp-content/uploads/2020/05/181101_excel14.gif)
- Insert a new column. (Or two. Or three! As many as you need.)
- In the new column(s), write
=LEFT(B1,2)
to extract the first 2 characters of the cell B1.=RIGHT(B1,8)
to extract the last 8 characters of the cell B1.=MID(B1,4,2)
to extract the 2 characters following the 4th character in B1. - To apply the changes to the cells below, drag down the blue square.
Pro tips
Pro tip 1:You can combine formulas to extract characters at all sorts ofcrazy positions. For example, the formula=LEN()
gives back the number of characters in a cell. So=LEFT(A1,LEN(A1)-2)
extracts the entire text in a cell except the last two characters. To separate the cellDatawrapper (Software)
into the two cellsDatawrapper
andSoftware
, you could use the formula=SPLIT(LEFT(A5,LEN(A5)-1),"("
. This formula first removes the last bracket and then splits the remaining cell content on(
.
Pro tip 2:Now that you learned to separate text, you can alsobring it together again. To combine the columnUS
from your cell A1 andTX
from B1 with a hyphen, use ampersands and write=A1&"-"&B1
.
Pro tip 3:You can extract content withLEFT()
,RIGHT()
,andMID()
not just from text cells, but also from number and date cells. If you want to apply formulas likeLEFT()
to yourdates, it helps to transform them into a text format first. To do so, use the formula=TEXT(A1, "MM/DD/YYYY")
. Instead ofMM/DD/YYYY
, you can use any combination ofthese date codesand/
,-
, a space, etc. For example,=TEXT(A1, "dd-mmm-yyyy")
will transform the date format1st of November 2019
to a text cell with the content01-Nov-2019
.
Pro tip 4: If you have empty cells in your column, and you want them stay empty after using a function like LEFT()
, you’ll need to check for these empty cells first. You can do so with the function ISBLANK()
, combined with an IF
function: =IF(ISBLANK(A1),"",LEFT(A1,3))
.
I hope this was helpful! If you need more help cleaning your data to prepare it for a charting tool like Datawrapper, visit our article“How to prepare your data for analysis and charting in Excel & Google Sheets.” And if you have any questions, please leave a comment or write to me atlisa@datawrapper.de.
![How to split and extract text from data columns in Excel & Google Sheets (5) How to split and extract text from data columns in Excel & Google Sheets (5)](https://i0.wp.com/blog.datawrapper.de/wp-content/uploads/2021/10/20210827-D81_2273-200x200.jpg)
Lisa Charlotte Muth
(she/her, @lisacmuth, @lisacmuth@vis.social) is Datawrapper’s head of communications. She writes about best practices in data visualization and thinks of new ways to excite you about charts and maps. Lisa lives in Berlin.
NEWSLETTER
Sign up to our newsletters to get notified about everything new on our blog.
Related Articles
How to match data with VLOOKUP in Excel & Google Sheets
October 20th, 2021
6 min
Calculating with your uploaded data in Datawrapper is now easier
June 2nd, 2020
4 min
How to import JSON data into Google Sheets to create a live COVID-19 chart
April 21st, 2020
6 min
All Blog Topics
All Blog Topics
I'm quite familiar with the concepts covered in that article! The piece discusses methods to manipulate data within spreadsheet software like Google Sheets, Excel, or LibreOffice Calc. It covers techniques like the SPLIT() function to separate data in columns based on a specific delimiter, as well as using LEFT(), RIGHT(), and MID() functions to extract portions of text from cells.
The article demonstrates two primary methods:
-
SPLIT() Function: This function helps divide data in a column based on a specified character (like "-"). It creates new columns to hold the split data.
-
LEFT(), RIGHT(), and MID() Functions: These functions help extract portions of text from cells based on their position within the text. LEFT() extracts characters from the beginning, RIGHT() from the end, and MID() from a specific starting point within the text.
It also offers some pro tips:
- Combining Formulas: You can combine functions to perform more complex data manipulation tasks.
- Rejoining Text: Using ampersands allows you to merge data back together.
- Manipulating Date Formats: Functions like TEXT() can transform date formats into text for easier manipulation.
- Handling Empty Cells: ISBLANK() function combined with IF statements ensures proper handling of empty cells when applying formulas.
The article essentially aims to equip users with the skills needed to clean and organize data effectively for visualization tools like Datawrapper, emphasizing the importance of proper data preparation for accurate and meaningful visual representation.
It's a comprehensive guide catering to individuals dealing with data processing and manipulation, providing them with practical methods and tips to optimize their data for visualization purposes.