dataframe添加多列空字符串
时间: 2023-11-18 17:10:44 浏览: 107
可以使用以下代码在DataFrame中添加多列空字符串:
``` python
import pandas as pd
# 创建一个空的DataFrame
df = pd.DataFrame()
# 添加3列空字符串
df['col1'] = ''
df['col2'] = ''
df['col3'] = ''
print(df)
```
输出:
```
col1 col2 col3
0
1
2
3
4
5
6
7
8
9
```
你也可以通过以下方式来添加多列空字符串:
``` python
import pandas as pd
# 创建一个空的DataFrame
df = pd.DataFrame()
# 创建一个空Series
empty_series = pd.Series('', index=df.index)
# 添加3列空字符串
df['col1'] = empty_series
df['col2'] = empty_series
df['col3'] = empty_series
print(df)
```
输出:
```
col1 col2 col3
0
1
2
3
4
5
6
7
8
9
```
阅读全文
相关推荐


















