Xlsx into csv7/8/2023 The above code just opens a CSV file that you need to name as “input_file.csv” and returns an Excel file, named “output_file.xlsx”. Suppose we just want to convert the file, without cleaning the data we can create a simple script like that: import pandas as pd #opening data open_data = pd.read_csv('input_file.csv') #saving to xlsx open_data.to_excel('output_file.xlsx') This way, we have simply saved the file in XLSX, naming it “grain_excel.xlsx”. Now, we are finally ready to convert the CVS to an XLSX we can easily do it with the following code: #saving to xlsx grain.to_excel('grain_excel.xlsx') We can do it with the following code: #selecting rows with 'Value'!=0 grain = grain.loc!=0] So, before saving the data for Tableau, since we are using Python it may be a good idea to remove these rows. If we explore the data a little bit, we can see that there are some countries with a production value of 0 tonnes. But when I tried to download the data in XLXS this was the error: I wanted to analyze grain production in Europe, and I found that the FAO website gives us some data (link here) to be downloaded and used. So the question was: how do I convert a CSV file to XLSX? Well, I can use Python! So, in this article, we’ll see how to do it. The fact is that Tableau accepts even CSV files, but we have to do some adjustments, and I prefer to use XLSX files. So I tried to download that data in CSV, and I had no trouble. The unfortunate event was that when trying to download the data in excel format - which is one of the formats that Tableau can accept - I got an error message. Some days ago, I wanted to analyze some data that could be downloaded from a website, for making some exercises with Tableau. Someone would say it’s a “jack of all trades, and master of none” but, in my opinion, its ability to be helpful in many tasks - from “basic programming” to machine learning - it’s the real power of Python. Python is a very flexible programming language.
0 Comments
Leave a Reply. |