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!
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!
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)