[英]creating one data frame using Pandas for multiple CSV files from many URL's
I'd like to create 1 data frame/structure using Pandas from multiple CSV files from URL's, keeping the initial header line. 我想使用来自URL的多个CSV文件中的Pandas创建1个数据框/结构,保留初始标题行。
With a single URL everything works as expected: 使用单个URL,一切都按预期工作:
df = pd.read_csv('http://www.URL1.csv')
I have attempted the following with multiple URL's: 我尝试了多个URL的以下内容:
df = pd.read_csv('http://www.URL1.csv', 'http://www.URL2.csv', ...)
However, when attempting to print for testing, the result is spaced out over thousands of lines and is far from the standard layout. 但是,在尝试打印进行测试时,结果会间隔数千行,并且远离标准布局。 Since I am new to
Pandas
, it is clear I am doing something wrong. 由于我是
Pandas
新手,很明显我做错了。
I'd expect the layout to be as followed: 我希望布局如下:
Header1 Header2 Header3 ...
DATA DATA DATA ...
I think you need list comprehension
with list
of urls
where output is list
of DataFrames
. 我认为你需要
list comprehension
与urls
list
,其中输出是DataFrames
list
。 Then use concat
for join together: 然后使用
concat
连接在一起:
urls = ['http://www.URL1.csv', 'http://www.URL2.csv']
dfs = [pd.read_csv(url) for url in urls]
df = pd.concat(dfs, ignore_index=True)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.