0

I just started Data science and I learned about the df.to_csv() method. However the code is giving an error. Thanks for the help.

import pandas as pd
df = pd.DataFrame({"Samuel":"65%","Daniel":"87%","Emily":"85%","Harris":"93%"})
df.to_csv('tocsvsample.csv')
  • 1
    The problem is how you create the dataframe. Try this: `df = pd.DataFrame({"Samuel":["65%"],"Daniel":["87%"], "Emily":["85%"],"Harris":["93%"]}) ` – DavideBrex Jun 20 '20 at 16:31
  • Thanks a lot David! I've seen a lot of differently-made dictionaries, where there are no brackets and only strings and numbers and sometimes there are brackets over the numbers. In what scenarios are the brackets used and not used? – Sriswaroop Koundinya Jun 20 '20 at 16:34
  • 1
    See this answer [here](https://stackoverflow.com/a/17840195/13328010) to understand better what was happening . In your case you could also apply `pd.DataFrame.from_records` and then the square brackets were not necessary. – DavideBrex Jun 20 '20 at 16:47

0 Answers0