Python Forum
Python & Dataframe basic question - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Data Science (https://python-forum.io/forum-44.html)
+--- Thread: Python & Dataframe basic question (/thread-25641.html)



Python & Dataframe basic question - georgialtr - Apr-06-2020

Hey one quick and very easy questions for all of you I am sure haha! Related to pandas & dataframes

So basically I just have to create a dataframe that contains the GDP Data from an already imported panda library. There is a dictionary under the word "links" containing the csv file with the data. The actual question is the following


" The dictionary links contain the CSV files with all the data. The value for the key GDP is the file that contains the GDP data. The value for the key unemployment contains the unemployment data.

In [44]:
[i] links={'GDP':'https://s3-api.us-geo.objectstorage.softlayer.net/cf-courses-data/CognitiveClass/PY0101EN/projects/coursera_project/clean_gdp.csv',\'unemployment':'https://s3-api.us-geo.objectstorage.softlayer.net/cf-courses-data/CognitiveClass/PY0101EN/projects/coursera_project/clean_unemployment.csv'
[/i]


Question 1: Create a dataframe that contains the GDP data and display the first five rows of the dataframe.
Use the dictionary links and the function pd.read_csv to create a Pandas dataframes that contains the GDP data.
Hint: links["GDP"] contains the path or name of the file.


In [52]:[python]links={'GDP':'https://s3-api.us-geo.objectstorage.softlayer.net/cf-courses-data/CognitiveClass/PY0101EN/projects/coursera_project/clean_gdp.csv'}
links_frame=pd.DataFrame(links, index=[0])
path_csv=links
df=pd.read_csv(path_csv)[python]



Writing [52] gives me the following errors:

What am I doing wrong?!! I am sure it is very simple but as I am very new to this I would appreciate your help!!!! Thank you all Smile Smile Smile


---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-52-336712d33cbe> in <module>
2 links_frame=pd.DataFrame(links, index=[0])
3 path_csv=links
----> 4 df=pd.read_csv(path_csv)

/opt/conda/envs/Python36/lib/python3.6/site-packages/pandas/io/parsers.py in parser_f(filepath_or_buffer, sep, delimiter, header, names, index_col, usecols, squeeze, prefix, mangle_dupe_cols, dtype, engine, converters, true_values, false_values, skipinitialspace, skiprows, skipfooter, nrows, na_values, keep_default_na, na_filter, verbose, skip_blank_lines, parse_dates, infer_datetime_format, keep_date_col, date_parser, dayfirst, iterator, chunksize, compression, thousands, decimal, lineterminator, quotechar, quoting, doublequote, escapechar, comment, encoding, dialect, tupleize_cols, error_bad_lines, warn_bad_lines, delim_whitespace, low_memory, memory_map, float_precision)
700 skip_blank_lines=skip_blank_lines)
701
--> 702 return _read(filepath_or_buffer, kwds)
703
704 parser_f.__name__ = name

/opt/conda/envs/Python36/lib/python3.6/site-packages/pandas/io/parsers.py in _read(filepath_or_buffer, kwds)
411 compression = _infer_compression(filepath_or_buffer, compression)
412 filepath_or_buffer, _, compression, should_close = get_filepath_or_buffer(
--> 413 filepath_or_buffer, encoding, compression)
414 kwds['compression'] = compression
415

/opt/conda/envs/Python36/lib/python3.6/site-packages/pandas/io/common.py in get_filepath_or_buffer(filepath_or_buffer, encoding, compression, mode)
230 if not is_file_like(filepath_or_buffer):
231 msg = "Invalid file path or buffer object type: {_type}"
--> 232 raise ValueError(msg.format(_type=type(filepath_or_buffer)))
233
234 return filepath_or_buffer, None, compression, False

ValueError: Invalid file path or buffer object type: <class 'dict'>