Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in BI by (1.6k points)

I want to visualize the CSV data in Tableau. ANd my data has category_list column, in which the values are separated by a vertical bar (|). However, it is not possible in Tableau to visualize the arrays inside the attributes. I used the pandas library of Python for manipulation of data. 

And my syntax is like :

import pandas as pd

companies = pd.read_csv("companies.csv")

I need to break the category_list column according to the vertical bar and stored in another CSV file.

I am attaching below the desired set of data and raw data :

Desired data set

Raw data:

So how can I get this result?

1 Answer

0 votes
by (3.1k points)

You can achieve this result without using python libraries like pandas. Below syntax will split the category_list column by vertical bar (|) into separate columns.

df.set_index('permalink').category_list.str.split('|', expand=True).stack().reset_index('permalink').rename(columns={0:'category'})

Then you can save this CSV file using pandas library as:

pd.to_csv("file_name")

OR 

You can do this in another way, Follow the below steps:

Step 1: Open the file in MS Excel

Step 2: Go to the Data tab

Step 3: Click on the Text to Columns option

Step 4: Select Delimited

Step 5: Set | or any other desired character to be the field separator/splitter

For more detail about Tableau data source check tableau tutorial.

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...