# import necessary libraries import pandas as pd import numpy as np # create a dummy array arr = np.arange(1,11).reshape(2,5) # display the array print(arr) # convert array into dataframe DF = pd.DataFrame(arr) # save the dataframe as a csv file DF.to_csv("data1.csv")
使用
numpy_array.tofile() 将一个 NumPy 数组转换为 CSV
该方法用于将一个数组写入文件中。创建一个数组,然后将其保存到 CSV
文件中。
1 2 3 4 5 6 7 8 9 10
# import the necessary library import numpy as np # create a dummy array arr = np.arange(1,11) # display the array print(arr) # use the tofile() method # and use ',' as a separator # as we have to generate a csv file arr.tofile('data2.csv', sep = ',')
使用
numpy.savetext() 将一个 NumPy 数组转换为 CSV
该方法用于保存一个数组到一个文本文件。创建一个数组,然后将其保存为
CSV 文件。
1 2 3 4 5 6 7 8
# import numpy library import numpy # create an array a = numpy.array([[1, 6, 4], [2, 4, 8], [3, 9, 1]]) # save array into csv file numpy.savetxt("data3.csv", a, delimiter = ",")
使用文件处理将 NumPy
数组转换为 CSV 文件
格式化器通过使用 str.format
函数和一对大括号()将一个或多个替换字段和占位符插入一个字符串中。该值将被插入占位符中,并与作为输入提供给
format函数的字符串连接。 with 是用来写进 CSV 文件的。
1 2 3 4 5 6 7 8 9 10 11 12
# import numpy library import numpy # create an array a = numpy.array([[1, 6, 4], [2, 4, 8], [3, 9, 1], [11, 23, 43]]) # save array into csv file rows = ["{},{},{}".format(i, j, k) for i, j, k in a] text = "\n".join(rows) withopen('data3.csv', 'w') as f: f.write(text)
\begin{document} \title{Your Article Title} \author{YourName\,\orcidlink{0000-0000-0000-0000}} \email[Contact author:]{YourEmail@xxx.com} \homepage[Visit:]{https://YourHomePageSite} \affiliation{School of Physics and Astronomy, Beijing Normal University, Beijing 100875, China} % \thanks{miscellaneous text} \date{\today} \preprint{Preprint} \keywords{electron-positron; laser} \begin{abstract} Your abstract \end{abstract}
% \pacs{05.45.-a; 02.60.-x; preprint}
\maketitle
\section{Introduction}
\section{Reference}
\bibliographystyle{unsrt} \bibliography{Reference.bib} % % 直接写引用信息,不推荐 % % \appendix % % \begin{thebibliography}{99}\suppressfloats % % \bibitem{ComDyn} % L. Carleson, T. W. Gamelin, Complex Dynamics, Springer, New York, % NY, 1993. % % \bibitem{AITJF} % S. Sutherland, An Introduction to Julia and Fatou Sets, in: C. Bandt, % M. Barnsley, R. Devaney, K. J. Falconer, V. Kannan, V. Kumar P.B. % (Eds.), Fractals, Wavelets, and their Applications, Springer Proceedings % in Mathematics $\&$ Statistics, Springer International Publishing, Cham, % pp. 37-60, 2014. % % \bibitem{MJFO} % M.-F. Danca, M. Fečkan, Mandelbrot set and Julia sets of fractional order, Nonlinear Dynamics 111(10), 9555-9570 (2023). % % \bibitem{MSPPCRF} % A. J. Mitchell, Existence of the Mandelbrot Set in the Parameter Planes of Certain Rational Functions, Theses and Dissertations, University of Wisconsin-Milwaukee (2016). % % \bibitem{GBBM} % H. Jang, Y. So, S. M. Marotta, Generalized baby Mandelbrot sets adorned with halos in families of rational maps, Journal of Difference Equations and Applications 23(3), 503-520 (2017). % % \end{thebibliography} \end{document}