У нас вы можете посмотреть бесплатно Python Pandas string output from DataFrame & using MySQL sample table as source by to_string() или скачать в максимальном доступном качестве, видео которое было загружено на ютуб. Для загрузки выберите вариант из формы ниже:
Если кнопки скачивания не
загрузились
НАЖМИТЕ ЗДЕСЬ или обновите страницу
Если возникают проблемы со скачиванием видео, пожалуйста напишите в поддержку по адресу внизу
страницы.
Спасибо за использование сервиса ClipSaver.ru
We can create string output or file by using data from Pandas DataFrame. We will first create one Pandas DataFrame by using some sample data. https://www.plus2net.com/python/panda... import pandas as pd my_dict={ 'NAME':['Ravi','Raju','Alex'], 'ID':[1,2,3],'MATH':[30,40,50], 'ENGLISH':[20,30,40] } df = pd.DataFrame(data=my_dict) After creating the DataFrame we used to_string() to create a string output df.to_json() This output we can use to create file to store the string. str1=df.to_string() # collect the string in a variable fob=open('D:\\my_data\\my_file.txt','w') # file object fob.write(str1) # write to file. fob.close() This will create the my_file.txt file . A different path can be given to store the file in different location in the system. We can add different options while generating the string. On important options is columns(), col_space, header, index, justify , max_width etc. df.to_string(columns=['NAME','ID']) From MySQL database using read_sql() We can connect to MySQL database by using SQLAlchemy engine and after connection we will create our DataFrame by using data from sample table by using read_sql. from sqlalchemy import create_engine my_conn = create_engine("mysql+mysqldb://root:test@localhost/my_tutorial") sql="SELECT * FROM student LIMIT 0,10" df=pd.read_sql(sql,my_conn) df.to_string() Here 10 rows of data from the student table is taken and displayed as string . Excel or CSV file to string From excel file we can create string by first creating the dataframe by reading the excel file by using the method read_excel() df=pd.read_excel("D:\\my_data\\student.xlsx") df.to_string() Similarly we can read csv file and generate JSON string df=pd.read_csv("D:\\my_data\\student.csv") df.to_string() #pandas_to_string #dataframetostring #pandastring