In this recipe, you will create DataFrame objects from other formats, such as .csv files, .json strings, and pickle files. A .csv file created using a spreadsheet application, valid JSON data received over web APIs, or valid pickle objects received over sockets can all be processed further using Python by converting them to DataFrame objects.
Loading pickled data received from untrusted sources can be unsafe. Please use read_pickle() with caution. You can find more details here: https://docs.python.org/3/library/pickle.html. If you are using this function on the pickle file created in the previous recipe, it is perfectly safe to use read_pickle().
Getting ready
Make sure you have followed the previous recipe before starting this recipe.
How to do it…
Execute the following steps for this recipe:
- Create a DataFrame object by reading a CSV file:
>>> pandas.read_csv('dataframe.csv')
We get the following output:
...