Python Forum
Python & Dataframe basic question
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python & Dataframe basic question
#1
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'>
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Basic help with a dataframe stylingpat 2 2,568 May-21-2021, 06:52 PM
Last Post: Caprone
  Simple pandas dataframe question popohoma 1 3,493 Jan-03-2019, 05:00 PM
Last Post: ashlardev
  Newbie question to return only the index of a dataframe zydjohn 0 2,521 Jan-22-2018, 03:40 PM
Last Post: zydjohn
  Question for dataframe to replace INF value zydjohn 0 5,118 Jan-15-2018, 10:00 PM
Last Post: zydjohn
  very simple dataframe question really_this_dumb 0 2,156 Jan-02-2018, 11:30 AM
Last Post: really_this_dumb
  Newbie question: how to generate dataframe and use multiple regression zydjohn 0 2,252 Dec-10-2017, 09:49 AM
Last Post: zydjohn
  Basic Question sitingbull25 2 3,297 Jul-26-2017, 04:07 PM
Last Post: sitingbull25
  pd.DataFrame question smw10c 2 3,967 Mar-30-2017, 09:12 PM
Last Post: smw10c

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020