-1

I have a string that is in the csv format, and I am wondering whether I can save it as a data frame without first saving it as a csv and then importing it as one.

Thanks!

kaufmane
  • 1
  • 1

1 Answers1

0

Yes, one of the possible approaches is to convert the string into a StringIO object and pass it to pd.DataFrame

from io import StringIO
import pandas as pd

string_data = StringIO("""col1,col2
    1,"a"
    2,"b"
    3,"c"
    4,"d"
    """)

df = pd.read_csv(string_data)
tax evader
  • 2,082
  • 1
  • 7
  • 9